[][src]Struct unsegen::base::grapheme_cluster::GraphemeCluster

pub struct GraphemeCluster { /* fields omitted */ }

A single grapheme cluster encoded in utf8. It may consist of multiple bytes or even multiple chars. For details on what a grapheme cluster is, read this or similar.

Implementations

impl GraphemeCluster[src]

pub fn as_str<'a>(&'a self) -> &'a str[src]

Get the underlying grapheme cluster as a String slice.

Examples:

use unsegen::base::GraphemeCluster;
assert_eq!(GraphemeCluster::try_from('a').unwrap().as_str(), "a");

pub fn space() -> Self[src]

Safely create a single space character (i.e., 0x20) grapheme cluster.

Examples:

use unsegen::base::GraphemeCluster;
assert_eq!(GraphemeCluster::space().as_str(), " ");

pub fn clear(&mut self)[src]

Replace the current cluster with a single space character (i.e., 0x20)

Examples:

use unsegen::base::GraphemeCluster;
let mut cluster = GraphemeCluster::try_from('a').unwrap();
cluster.clear();
assert_eq!(cluster.as_str(), " ");

pub fn try_from(c: char) -> Result<Self, GraphemeClusterError>[src]

Try to create a grapheme cluster from a character. If c is not a single grapheme cluster, a GraphemeClusterError is returned.

Examples:

use unsegen::base::GraphemeCluster;
assert_eq!(GraphemeCluster::try_from('a').unwrap().as_str(), "a");

pub fn all_from_str<'a>(string: &'a str) -> GraphemeClusterIter<'a>

Notable traits for GraphemeClusterIter<'a>

impl<'a> Iterator for GraphemeClusterIter<'a> type Item = GraphemeCluster;
[src]

Retrieve all grapheme clusters from the given string.

Examples:

use unsegen::base::GraphemeCluster;
let mut clusters = GraphemeCluster::all_from_str("ab d");
assert_eq!(clusters.next(), Some(GraphemeCluster::try_from('a').unwrap()));
assert_eq!(clusters.next(), Some(GraphemeCluster::try_from('b').unwrap()));
assert_eq!(clusters.next(), Some(GraphemeCluster::try_from(' ').unwrap()));
assert_eq!(clusters.next(), Some(GraphemeCluster::try_from('d').unwrap()));
assert_eq!(clusters.next(), None);

pub fn width(&self) -> usize[src]

Calculate the unicode width of the given grapheme cluster.

Examples:

use unsegen::base::GraphemeCluster;
assert_eq!(GraphemeCluster::try_from('a').unwrap().width(), 1);

Trait Implementations

impl Clone for GraphemeCluster[src]

impl Debug for GraphemeCluster[src]

impl FromStr for GraphemeCluster[src]

type Err = GraphemeClusterError

The associated error which can be returned from parsing.

impl PartialEq<GraphemeCluster> for GraphemeCluster[src]

impl StructuralPartialEq for GraphemeCluster[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.