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

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

The resulting type after applying the + operator.
source§

fn add(self, rhs: Translation) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Translation> for String

Available on crate feature 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");
§

type Output = String

The resulting type after applying the + operator.
source§

fn add(self, rhs: Translation) -> Self::Output

Performs the + operation. Read more
source§

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)

Performs the += operation. Read more
source§

impl AddAssign<Translation> for String

Available on crate feature 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)

Performs the += operation. Read more
source§

impl Clone for Translation

source§

fn clone(&self) -> Translation

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Translation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Translation

Available on crate feature 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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Translation

Formats this Translation. Behaves like formatting your typical String.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Translation> for String

Available on crate feature 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>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

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§

fn from(ch: C) -> Self

Converts to this type from the input type.
source§

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>,

Creates a value from an iterator. Read more
source§

impl FromIterator<Translation> for String

Available on crate feature 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>,

Creates a value from an iterator. Read more
source§

impl Into<Option<String>> for Translation

Available on crate feature 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§

fn into(self) -> Option<String>

Converts this type into the (usually inferred) input type.
source§

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§

fn eq(&self, other: &S) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Translation> for Translation

source§

fn eq(&self, other: &Translation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Translation

Available on crate feature serde only.

Serializes this Translation.

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"}"#);
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Translation

source§

impl Eq for Translation

source§

impl StructuralEq for Translation

source§

impl StructuralPartialEq for Translation

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,