decancer

Struct Options

Source
pub struct Options(/* private fields */);
Expand description

A configuration struct where you can customize decancer’s behavior.

By default, decancer cures as much characters as possible and turns all the output characters to lowercase.

If you don’t plan on using this struct and only using decancer’s defaults, it’s recommended to disable the default options feature flag to optimize away unnecessary option checks.

use decancer::Options;

// by default, all options are disabled
let _options = Options::default();

Implementations§

Source§

impl Options

Source

pub const fn all() -> Self

Creates a new configuration where every option is enabled.

Source

pub const fn pure_homoglyph() -> Self

Creates a new configuration that prevents decancer from curing characters from major foreign writing systems, including diacritics.

Source

pub const fn retain_capitalization(self) -> Self

Prevents decancer from changing all characters to lowercase. Therefore, if the input character is in uppercase, the output character will be in uppercase as well.

NOTE: Many confusables are neither an uppercase or a lowercase character. Therefore, the decancer defaults to displaying the translation in lowercase:

use decancer::{Translation, Options};
use std::borrow::Cow;

let options = Options::default()
  .retain_capitalization();

assert_eq!('🆐'.to_lowercase().collect::<String>(), '🆐'.to_uppercase().collect::<String>());
assert_eq!(decancer::cure_char('🆐', options), Translation::String(Cow::Borrowed("dj")));
Source

pub const fn disable_bidi(self) -> Self

Prevents decancer from applying the Unicode Bidirectional Algorithm. Use this only when you don’t expect any right-to-left characters. Enabling this option has no effect if it’s called on cure_char.

NOTE: This speeds up the function call, but can break right-to-left characters. It’s highly recommended to also use retain_arabic and retain_hebrew.

Source

pub const fn retain_diacritics(self) -> Self

Prevents decancer from curing characters with diacritics or accents.

NOTE: Decancer can still cure standalone diacritic characters, which is used in Zalgo texts.

Source

pub const fn retain_japanese(self) -> Self

Prevents decancer from curing all katakana and hiragana characters.

NOTE: To also provent decancer from curing kanji characters, use retain_chinese.

Source

pub const fn retain_emojis(self) -> Self

Prevents decancer from curing all emojis.

Source

pub const fn retain_turkish(self) -> Self

Prevents decancer from curing all turkish characters.

NOTE: To also prevent decancer from curing the uppercase dotted i character (İ), use retain_capitalization.

Source

pub const fn ascii_only(self) -> Self

Removes all non-ASCII characters from the result.

Source

pub const fn alphanumeric_only(self) -> Self

Removes all non-alphanumeric characters from the result.

Source

pub const fn retain_greek(self) -> Self

Prevents decancer from curing all greek characters.

Source

pub const fn retain_cyrillic(self) -> Self

Prevents decancer from curing all cyrillic characters.

Source

pub const fn retain_hebrew(self) -> Self

Prevents decancer from curing all hebrew characters.

Source

pub const fn retain_arabic(self) -> Self

Prevents decancer from curing all arabic characters.

Source

pub const fn retain_devanagari(self) -> Self

Prevents decancer from curing all devanagari characters.

Source

pub const fn retain_bengali(self) -> Self

Prevents decancer from curing all bengali characters.

Source

pub const fn retain_armenian(self) -> Self

Prevents decancer from curing all armenian characters.

Source

pub const fn retain_gujarati(self) -> Self

Prevents decancer from curing all gujarati characters.

Source

pub const fn retain_tamil(self) -> Self

Prevents decancer from curing all tamil characters.

Source

pub const fn retain_thai(self) -> Self

Prevents decancer from curing all thai characters.

Source

pub const fn retain_lao(self) -> Self

Prevents decancer from curing all lao characters.

Source

pub const fn retain_burmese(self) -> Self

Prevents decancer from curing all burmese characters.

Source

pub const fn retain_khmer(self) -> Self

Prevents decancer from curing all khmer characters.

Source

pub const fn retain_mongolian(self) -> Self

Prevents decancer from curing all mongolian characters.

Source

pub const fn retain_chinese(self) -> Self

Prevents decancer from curing all chinese characters.

Source

pub const fn retain_korean(self) -> Self

Prevents decancer from curing all korean characters.

Source

pub const fn retain_braille(self) -> Self

Prevents decancer from curing all braille characters.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

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 Default for Options

Source§

fn default() -> Options

Returns the “default value” for a type. Read more
Source§

impl Hash for Options

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Options

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Options

Source§

impl Eq for Options

Source§

impl StructuralPartialEq for Options

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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 T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.