Enum decancer::Translation
source · pub enum Translation {
Character(char),
String(&'static str),
None,
}Expand description
The translation for a single character/codepoint.
Variants§
Character(char)
A single unicode character.
String(&'static str)
A multi-character ASCII string.
None
This suggests that the translation is an empty string. You can get this when the input character is a control character, surrogate, combining character, private use character, byte order character, or any invalid unicode value (e.g beyond char::MAX).
Trait Implementations§
source§impl Add<Translation> for CuredString
impl Add<Translation> for CuredString
A helper implementation for appending a Translation to a CuredString.
Examples
Basic usage:
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let mut cured = decancer::cure(text);
for cured_char in text.chars().map(decancer::cure_char) {
cured = cured + cured_char;
}
assert_eq!(cured, "very funny textvery funny text");§type Output = CuredString
type Output = CuredString
+ operator.source§impl Add<Translation> for String
Available on crate feature std only.
impl Add<Translation> for String
std only.A helper implementation for appending a Translation to a String.
Examples
Basic usage:
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let mut cured = String::with_capacity(text.len());
for cured_char in text.chars().map(decancer::cure_char) {
cured = cured + cured_char;
}
assert_eq!(cured, "very funny text");source§impl AddAssign<Translation> for CuredString
impl AddAssign<Translation> for CuredString
A helper implementation for appending a Translation to a CuredString.
Examples
Basic usage:
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let mut cured = decancer::cure(text);
for cured_char in text.chars().map(decancer::cure_char) {
cured += cured_char;
}
assert_eq!(cured, "very funny textvery funny text");source§fn add_assign(&mut self, rhs: Translation)
fn add_assign(&mut self, rhs: Translation)
+= operation. Read moresource§impl AddAssign<Translation> for String
Available on crate feature std only.
impl AddAssign<Translation> for String
std only.A helper implementation for appending a Translation to a String.
Examples
Basic usage:
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let mut cured = String::with_capacity(text.len());
for cured_char in text.chars().map(decancer::cure_char) {
cured += cured_char;
}
assert_eq!(cured, "very funny text");source§fn add_assign(&mut self, rhs: Translation)
fn add_assign(&mut self, rhs: Translation)
+= operation. Read moresource§impl Clone for Translation
impl Clone for Translation
source§fn clone(&self) -> Translation
fn clone(&self) -> Translation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for Translation
impl Debug for Translation
source§impl<'de> Deserialize<'de> for Translation
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Translation
serde only.Deserializes and cures a character.
Examples
Basic usage:
use decancer::Translation;
use serde::Deserialize;
#[derive(Deserialize)]
struct Decancered {
translation: Translation,
}
let json = r#"{"translation": "ӕ"}"#;
let decancered: Decancered = serde_json::from_str(json).unwrap();
assert!(matches!(decancered.translation, Translation::String("ae")));source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl Display for Translation
impl Display for Translation
Formats this Translation. Behaves like formatting your typical String.
source§impl Extend<Translation> for CuredString
impl Extend<Translation> for CuredString
Extends a CuredString with an iterator that yields Translations.
Examples
Basic usage:
let mut text = decancer::cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣");
text.extend([decancer::cure_char('E'), decancer::cure_char('E')]);
assert_eq!(text, "very funny textee");source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Translation>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = Translation>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl Extend<Translation> for String
Available on crate feature std only.
impl Extend<Translation> for String
std only.Extends a String with an iterator that yields Translations.
Examples
Basic usage:
let mut text = String::new();
text.extend([decancer::cure_char('E'), decancer::cure_char('E')]);
assert_eq!(text, "ee");source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Translation>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = Translation>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<C> From<C> for Translationwhere
C: Into<u32>,
impl<C> From<C> for Translationwhere C: Into<u32>,
Cures a single character/unicode codepoint.
Examples
Most of the time, this would yield only a single unicode character:
use decancer::Translation;
let cured_e = Translation::from('E');
assert!(matches!(cured_e, Translation::Character('e')));However, for several special cases, it would yield an ASCII &'static str:
use decancer::Translation;
let cured_ae = Translation::from('ӕ');
assert!(matches!(cured_ae, Translation::String("ae")));If your unicode character is a control character, surrogate, combining character, private use character, byte order character, or any invalid unicode value (e.g beyond char::MAX), you would get None:
use decancer::Translation;
let cured_surrogate = Translation::from(0xD800u32);
assert!(matches!(cured_surrogate, Translation::None));source§impl FromIterator<Translation> for CuredString
impl FromIterator<Translation> for CuredString
A helper implementation for joining several Translations into one CuredString.
Examples
Basic usage:
use decancer::CuredString;
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let cured: CuredString = text.chars().map(decancer::cure_char).collect();
// cured here is a CuredString struct wrapping over the cured string
// for comparison purposes, it's more recommended to use the methods provided by the CuredString struct.
assert_eq!(cured, "very funny text");
assert!(cured.starts_with("very"));
assert!(cured.contains("funny"));
assert!(cured.ends_with("text"));
// retrieve the String inside and consume the struct.
let _output_str = cured.into_str();source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Translation>,
fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = Translation>,
source§impl FromIterator<Translation> for String
Available on crate feature std only.
impl FromIterator<Translation> for String
std only.A helper implementation for joining several Translations into one String.
Examples
Basic usage:
let text = "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣";
let cured: String = text.chars().map(decancer::cure_char).collect();
assert_eq!(cured, "very funny text");source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Translation>,
fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = Translation>,
source§impl Into<Option<String>> for Translation
Available on crate feature std only.
impl Into<Option<String>> for Translation
std only.Coerces this Translation to an Option<String>.
Examples
A non-Translation::None value would yield a Some(String):
use decancer::Translation;
let cured_e: Option<String> = decancer::cure_char('E').into();
assert_eq!(cured_e, Some(String::from("e")));Otherwise, a Translation::None value would yield a None:
use decancer::Translation;
let cured_surrogate: Option<String> = decancer::cure_char(0xD800u32).into();
assert!(cured_surrogate.is_none());source§impl<S> PartialEq<S> for Translationwhere
S: AsRef<str> + ?Sized,
impl<S> PartialEq<S> for Translationwhere S: AsRef<str> + ?Sized,
Checks if this Translation is similar to another string.
Examples
Basic usage:
let cured = decancer::cure_char('E');
assert_eq!(cured, "e");And since it checks if the strings are similar, please note that this is valid too:
let cured = decancer::cure_char('E');
// it assumes that e is similar to 3
assert_eq!(cured, "3");source§impl PartialEq<Translation> for Translation
impl PartialEq<Translation> for Translation
source§fn eq(&self, other: &Translation) -> bool
fn eq(&self, other: &Translation) -> bool
self and other values to be equal, and is used
by ==.source§impl Serialize for Translation
Available on crate feature serde only.
impl Serialize for Translation
serde only.Serializes this Translation.
- A
Translation::Characterwould serialize into acharacter. - A
Translation::Stringwould serialize into astring. - A
Translation::Nonewould serialize into aunit.
Examples
Basic usage:
use decancer::Translation;
use serde::Serialize;
#[derive(Serialize)]
struct Decancered {
translation: Translation,
}
let decancered = Decancered {
translation: decancer::cure_char('ӕ')
};
assert_eq!(serde_json::to_string(&decancered).unwrap(), r#"{"translation":"ae"}"#);