Seperate nightly-features into subfeatures

main
John Zacarias Jekel 1 year ago
parent 97cc72fc47
commit 2be7ede4ee
  1. 4
      Cargo.toml
  2. 2
      src/helpers.rs
  3. 6
      src/lib.rs
  4. 44
      src/translate_strings.rs
  5. 32
      src/translate_words.rs

@ -16,7 +16,9 @@ documentation = "https://docs.rs/anslatortray/latest/anslatortray/"
[features]
default = []
nightly-features = []
nightly-features = ["nightly-features-benches", "nightly-features-generics"]
nightly-features-benches = []
nightly-features-generics = []
[lib]
name = "anslatortray"

@ -55,7 +55,7 @@ pub(crate) fn push_slice_to_vector<T: Clone>(vec: &mut Vec<T>, slice: &[T]) {
}
//Capitalizes an ASCII/byte string at compile time
#[cfg(feature = "nightly-features")]//Not unstable on it's own, but only needed by things enabled by nightly-features
#[cfg(feature = "nightly-features-generics")]//Not unstable on it's own, but only needed by things enabled by nightly-features
pub(crate) const fn capitalize_ascii<const LEN: usize>(word: &[u8; LEN]) -> [u8; LEN] {
let mut capitalized = [0u8; LEN];
let mut i: usize = 0;

@ -72,9 +72,9 @@
/* Nightly Features */
//Only enabled if the relevant Cargo feature is
#![cfg_attr(feature = "nightly-features", feature(test))]
#![cfg_attr(feature = "nightly-features", feature(adt_const_params))]
#![cfg_attr(feature = "nightly-features", feature(generic_const_exprs))]
#![cfg_attr(feature = "nightly-features-benches", feature(test))]
#![cfg_attr(feature = "nightly-features-generics", feature(adt_const_params))]
#![cfg_attr(feature = "nightly-features-generics", feature(generic_const_exprs))]
/* Imports */

@ -9,8 +9,10 @@
/* Imports */
use crate::translate_words::translate_word_with_style_reuse_buffers;
#[cfg(feature = "nightly-features-generics")]
use crate::translate_words::translate_word_with_style_reuse_buffers_generic;
use crate::translate_words::translate_word_with_style_reuse_buffers_ascii;
#[cfg(feature = "nightly-features-generics")]
use crate::translate_words::translate_word_with_style_reuse_buffers_ascii_generic;
/* Functions */
@ -120,9 +122,9 @@ pub fn translate_ascii(english: &str) -> String {
///assert_eq!(translate_way("Hyphens-are-difficult-aren't-they?"), "Yphenshay-areway-ifficultday-arenway't-eythay?");
///```
pub fn translate_way(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style(english, "ay", "way");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_generic::<"ay", "way", "AY", "WAY">(english);
}
@ -159,9 +161,9 @@ pub fn translate_way(english: &str) -> String {
///assert_eq!(translate_way_ascii("Hyphens-are-difficult-aren't-they?"), "Yphenshay-areway-ifficultday-arenway't-eythay?");
///```
pub fn translate_way_ascii(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style_ascii(english, "ay", "way");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_ascii_generic::<b"ay", b"way", b"AY", b"WAY">(english);
}
@ -196,9 +198,9 @@ pub fn translate_way_ascii(english: &str) -> String {
///assert_eq!(translate_yay("Hyphens-are-difficult-aren't-they?"), "Yphenshay-areyay-ifficultday-arenyay't-eythay?");
///```
pub fn translate_yay(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style(english, "ay", "yay");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_generic::<"ay", "yay", "AY", "YAY">(english);
}
@ -235,9 +237,9 @@ pub fn translate_yay(english: &str) -> String {
///assert_eq!(translate_yay_ascii("Hyphens-are-difficult-aren't-they?"), "Yphenshay-areyay-ifficultday-arenyay't-eythay?");
///```
pub fn translate_yay_ascii(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style_ascii(english, "ay", "yay");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_ascii_generic::<b"ay", b"yay", b"AY", b"YAY">(english);
}
@ -272,9 +274,9 @@ pub fn translate_yay_ascii(english: &str) -> String {
///assert_eq!(translate_hay("Hyphens-are-difficult-aren't-they?"), "Yphenshay-arehay-ifficultday-arenhay't-eythay?");
///```
pub fn translate_hay(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style(english, "ay", "hay");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_generic::<"ay", "hay", "AY", "HAY">(english);
}
@ -311,9 +313,9 @@ pub fn translate_hay(english: &str) -> String {
///assert_eq!(translate_hay_ascii("Hyphens-are-difficult-aren't-they?"), "Yphenshay-arehay-ifficultday-arenhay't-eythay?");
///```
pub fn translate_hay_ascii(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style_ascii(english, "ay", "hay");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_ascii_generic::<b"ay", b"hay", b"AY", b"HAY">(english);
}
@ -346,9 +348,9 @@ pub fn translate_hay_ascii(english: &str) -> String {
///assert_eq!(translate_ferb("Hyphens-are-difficult-aren't-they?"), "Yphensherb-areferb-ifficultderb-arenferb't-eytherb?");
///```
pub fn translate_ferb(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style(english, "erb", "ferb");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_generic::<"erb", "ferb", "ERB", "FERB">(english);
}
@ -383,9 +385,9 @@ pub fn translate_ferb(english: &str) -> String {
///assert_eq!(translate_ferb_ascii("Hyphens-are-difficult-aren't-they?"), "Yphensherb-areferb-ifficultderb-arenferb't-eytherb?");
///```
pub fn translate_ferb_ascii(english: &str) -> String {
#[cfg(not(feature = "nightly-features"))]
#[cfg(not(feature = "nightly-features-generics"))]
return translate_with_style_ascii(english, "erb", "ferb");
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
return translate_with_style_ascii_generic::<b"erb", b"ferb", b"ERB", b"FERB">(english);
}
@ -510,7 +512,7 @@ pub fn translate_with_style(english: &str, suffix_lower: &str, special_case_suff
}
///TODO description, tests, examples
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
pub fn translate_with_style_generic <
const SUFFIX_LOWER: &'static str, const SPECIAL_CASE_SUFFIX_LOWER: &'static str,
const SUFFIX_UPPER: &'static str, const SPECIAL_CASE_SUFFIX_UPPER: &'static str
@ -727,7 +729,7 @@ pub fn translate_with_style_ascii(english: &str, suffix_lower: &str, special_cas
///TODO description, tests, examples
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
pub fn translate_with_style_ascii_generic <
const SUFFIX_LOWER: &'static [u8], const SPECIAL_CASE_SUFFIX_LOWER: &'static [u8],
const SUFFIX_UPPER: &'static [u8], const SPECIAL_CASE_SUFFIX_UPPER: &'static [u8]
@ -827,7 +829,7 @@ pub fn translate_with_style_ascii_byte(english: &[u8], suffix_lower: &[u8], spec
//TODO this would be better but we can't have some const generics depending on others
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
pub fn translate_with_style_ascii_byte_generic <
const SUFFIX_LEN: usize, const SUFFIX_LOWER: [u8],
const SPECIAL_CASE_SUFFIX_LEN: usize, const SPECIAL_CASE_SUFFIX_LOWER: [u8]
@ -1004,8 +1006,8 @@ mod tests {
/* Benches */
#[cfg_attr(feature = "nightly-features", cfg(test))]
#[cfg(feature = "nightly-features")]
#[cfg_attr(feature = "nightly-features-benches", cfg(test))]
#[cfg(feature = "nightly-features-benches")]
mod benches {
extern crate test;
use test::Bencher;

@ -89,7 +89,7 @@ pub(crate) fn translate_word_with_style_reuse_buffers (
}
}
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
pub(crate) fn translate_word_with_style_reuse_buffers_generic <
const SUFFIX_LOWER: &'static str, const SPECIAL_CASE_SUFFIX_LOWER: &'static str,
const SUFFIX_UPPER: &'static str, const SPECIAL_CASE_SUFFIX_UPPER: &'static str
@ -250,7 +250,7 @@ pub(crate) fn translate_word_with_style_reuse_buffers_ascii_generic <
const SUFFIX_UPPER: [u8; SUFFIX_LEN], const SPECIAL_CASE_SUFFIX_UPPER: [u8; SPECIAL_CASE_SUFFIX_LEN]
> (
*/
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
pub(crate) fn translate_word_with_style_reuse_buffers_ascii_generic <
const SUFFIX_LOWER: &'static [u8], const SPECIAL_CASE_SUFFIX_LOWER: &'static [u8],
const SUFFIX_UPPER: &'static [u8], const SPECIAL_CASE_SUFFIX_UPPER: &'static [u8]
@ -373,7 +373,7 @@ mod tests {
}
#[test]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn test_translate_word_with_style_generic() {
//TODO test with other suffixes perhaps?
let suffix = "ay";
@ -445,7 +445,7 @@ mod tests {
}
#[test]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn test_translate_word_with_style_ascii_generic() {
//TODO test with other suffixes perhaps?
let suffix = "ay";
@ -498,7 +498,7 @@ mod tests {
return pig_latin_word;
}
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn translate_word_with_style_generic <
const SUFFIX_LOWER: &'static str, const SPECIAL_CASE_SUFFIX_LOWER: &'static str,
const SUFFIX_UPPER: &'static str, const SPECIAL_CASE_SUFFIX_UPPER: &'static str
@ -540,7 +540,7 @@ mod tests {
return std::str::from_utf8(pig_latin_word.as_slice()).unwrap().to_string();
}
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn translate_word_with_style_ascii_generic <
const SUFFIX_LOWER: &'static [u8], const SPECIAL_CASE_SUFFIX_LOWER: &'static [u8],
const SUFFIX_UPPER: &'static [u8], const SPECIAL_CASE_SUFFIX_UPPER: &'static [u8]
@ -565,8 +565,8 @@ mod tests {
/* Benches */
#[cfg_attr(feature = "nightly-features", cfg(test))]
#[cfg(feature = "nightly-features")]
#[cfg_attr(feature = "nightly-features-benches", cfg(test))]
#[cfg(feature = "nightly-features-benches")]
mod benches {
extern crate test;
use test::Bencher;
@ -653,7 +653,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn generic_way_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = String::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = String::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -675,7 +675,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn generic_yay_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = String::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = String::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -697,7 +697,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn generic_hay_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = String::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = String::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -719,7 +719,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn generic_ferb_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = String::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = String::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -821,7 +821,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn ascii_generic_way_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = Vec::<u8>::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -843,7 +843,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn ascii_generic_yay_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = Vec::<u8>::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -865,7 +865,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn ascii_generic_hay_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = Vec::<u8>::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
@ -887,7 +887,7 @@ mod benches {
}
#[bench]
#[cfg(feature = "nightly-features")]
#[cfg(feature = "nightly-features-generics")]
fn ascii_generic_ferb_the_word_translator(b: &mut Bencher) {
let mut pig_latin_word = Vec::<u8>::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word

Loading…
Cancel
Save