Runes

Struct Runes 

Source
pub struct Runes<'g> { /* private fields */ }
Expand description

Represents a slice of bytes which can be automatically parsed into a sequence of Rune(s)

Β§Examples

 use utf8_rune::Runes;
 let parts = Runes::new("πŸ‘©πŸ»β€πŸš’πŸ‘ŒπŸΏπŸ§‘πŸ½β€πŸš’πŸ‘¨β€πŸš’πŸŒΆοΈπŸŽΉπŸ’”πŸ”₯❀️‍πŸ”₯β€οΈβ€πŸ©Ή");
 assert_eq!(
     parts
         .to_vec()
         .iter()
         .map(|rune| rune.to_string())
         .collect::<Vec<String>>(),
     vec![
         "πŸ‘©πŸ»β€πŸš’",
         "πŸ‘ŒπŸΏ",
         "πŸ§‘πŸ½β€πŸš’",
         "πŸ‘¨β€πŸš’",
         "🌢️",
         "🎹",
         "πŸ’”",
         "πŸ”₯",
         "❀️‍πŸ”₯",
         "β€οΈβ€πŸ©Ή",
     ]
 );
use utf8_rune::Runes;
let runes = Runes::new("πŸ‘ŒπŸ‘ŒπŸ»πŸ‘ŒπŸΌπŸ‘ŒπŸ½πŸ‘ŒπŸΎπŸ‘ŒπŸΏ");

assert_eq!(runes.rune_indexes(), vec![
    (0, 4),
    (4, 8),
    (12, 8),
    (20, 8),
    (28, 8),
    (36, 8),
]);
assert_eq!(runes.len(), 6);
assert_eq!(runes[0], "πŸ‘Œ");
assert_eq!(runes[1], "πŸ‘ŒπŸ»");
assert_eq!(runes[2], "πŸ‘ŒπŸΌ");
assert_eq!(runes[3], "πŸ‘ŒπŸ½");
assert_eq!(runes[4], "πŸ‘ŒπŸΎ");
assert_eq!(runes[5], "πŸ‘ŒπŸΏ");

ImplementationsΒ§

SourceΒ§

impl<'g> Runes<'g>

Source

pub fn new<T: Display>(input: T) -> Runes<'g>

Source

pub fn allocate<T: Display>(input: T) -> Result<Runes<'g>>

Source

pub fn empty() -> Result<Runes<'g>>

Source

pub fn as_str(&self) -> &'g str

Source

pub fn as_bytes(&self) -> &'g [u8] β“˜

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn as_debug(&self, indent: Option<usize>) -> String

Source

pub fn indexes(&self) -> Vec<usize>

Source

pub fn rune_indexes(&self) -> Vec<(usize, usize)>

Source

pub fn get(&self, index: usize) -> Option<Rune>

Source

pub fn to_vec(&self) -> Vec<Rune>

Trait ImplementationsΒ§

SourceΒ§

impl<'g> Clone for Runes<'g>

SourceΒ§

fn clone(&self) -> Runes<'g>

Returns a duplicate 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<'g> Debug for Runes<'g>

SourceΒ§

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

Formats the value using the given formatter. Read more
SourceΒ§

impl<'g> Default for Runes<'g>

SourceΒ§

fn default() -> Runes<'g>

Returns the β€œdefault value” for a type. Read more
SourceΒ§

impl<'g> Display for Runes<'g>

SourceΒ§

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

Formats the value using the given formatter. Read more
SourceΒ§

impl<'g> From<&String> for Runes<'g>

SourceΒ§

fn from(s: &String) -> Runes<'g>

Converts to this type from the input type.
SourceΒ§

impl<'g> From<&str> for Runes<'g>

SourceΒ§

fn from(s: &str) -> Runes<'g>

Converts to this type from the input type.
SourceΒ§

impl<'g> From<String> for Runes<'g>

SourceΒ§

fn from(s: String) -> Runes<'g>

Converts to this type from the input type.
SourceΒ§

impl<'g> Index<usize> for Runes<'g>

SourceΒ§

type Output = &'g str

The returned type after indexing.
SourceΒ§

fn index(&self, index: usize) -> &&'g str

Performs the indexing (container[index]) operation. Read more

Auto Trait ImplementationsΒ§

Β§

impl<'g> Freeze for Runes<'g>

Β§

impl<'g> RefUnwindSafe for Runes<'g>

Β§

impl<'g> !Send for Runes<'g>

Β§

impl<'g> !Sync for Runes<'g>

Β§

impl<'g> Unpin for Runes<'g>

Β§

impl<'g> UnwindSafe for Runes<'g>

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, dest: *mut u8)

πŸ”¬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

SourceΒ§

fn to_string(&self) -> String

Converts the given value to a String. 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.