Struct strcursor::grapheme::Gc [] [src]

pub struct Gc(_);

A slice of a single Unicode grapheme cluster (GC) (akin to str).

A grapheme cluster is a single visual "unit" in Unicode text, and is composed of at least one Unicode code point, possibly more.

This type is a wrapper around str that enforces the additional invariant that it will always contain exactly one grapheme cluster. This allows some operations (such as extracting the base code point) simpler.

Why Grapheme Clusters?

The simplest example is the distinction between "é" ("Latin Small Letter E with Acute") and "é" ("Latin Small Letter E", "Combining Acute Accent"): the first is one code point, the second is two.

In Rust, the char type is a single code point. As a result, treating it as a "character" is incorrect for the same reason that using u8 is: it excludes many legitimate characters. It can also cause issues whereby naive algorithms may corrupt text by considering components of a grapheme cluster separately. For example, truncating a string to "10 characters" using chars can lead to logical characters being broken apart, potentially changing their meaning.

One inconvenience when dealing with grapheme clusters in Rust is that they are not accurately represented by any type more-so than a regular &str. However, operations that might make sense on an individual character (such as asking whether it is in the ASCII range, or is numeric) don't make sense on a full string. In addition, a &str can be empty or contain more than one grapheme cluster.

Hence, this type guarantees that it always represents exactly one Unicode grapheme cluster.

Methods

impl Gc
[src]

fn from_str(s: &str) -> Option<&Gc>

Create a new Gc from the given string slice.

The slice must contain exactly one grapheme cluster. In the event that the input is empty, or contains more than one grapheme cluster, this function will return None.

See: split_from.

unsafe fn from_str_unchecked(s: &str) -> &Gc

Create a new Gc from the given string slice.

This function does not check to ensure the provided slice is a single, valid grapheme cluster.

fn split_from(s: &str) -> Option<(&Gc, &str)>

Try to split a single grapheme cluster from the start of s.

Returns None if the given string was empty.

fn len(&self) -> usize

Returns the length of this grapheme cluster in bytes.

fn has_marks(&self) -> bool

Does this grapheme cluster have additional marks applied to it?

This is true if the cluster is comprised of more than a single code point.

fn as_bytes(&self) -> &[u8]

Converts this to a byte slice.

fn as_str(&self) -> &str

Converts this to a string slice.

fn base_char(&self) -> char

Returns the "base" code point.

That is, this returns the first code point in the cluster.

fn base(&self) -> &Gc

Returns the "base" code point as a grapheme cluster.

This is equivalent to converting this GC into a string slice, then slicing off the bytes that make up the first code point.

fn mark_str(&self) -> &str

Returns the combining marks as a string slice.

The result of this method may be empty, or of arbitrary length.

fn chars(&self) -> Chars

An iterator over the code points of this grapheme cluster.

fn char_indices(&self) -> CharIndices

An iterator over the code points of this grapheme cluster, and their associated byte offsets.

fn bytes(&self) -> Bytes

An iterator over the bytes of this grapheme cluster.

fn to_lowercase(&self) -> ToLowercase

Returns an iterator over the code points in the lower case equivalent of this grapheme cluster.

fn to_uppercase(&self) -> ToUppercase

Returns an iterator over the code points in the upper case equivalent of this grapheme cluster.

Trait Implementations

impl Hash for Gc
[src]

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

Feeds this value into the state given, updating the hasher as necessary.

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

Feeds a slice of this type into the state provided.

impl PartialOrd for Gc
[src]

fn partial_cmp(&self, __arg_0: &Gc) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, __arg_0: &Gc) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, __arg_0: &Gc) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, __arg_0: &Gc) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, __arg_0: &Gc) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for Gc
[src]

fn cmp(&self, __arg_0: &Gc) -> Ordering

This method returns an Ordering between self and other. Read more

impl PartialEq for Gc
[src]

fn eq(&self, __arg_0: &Gc) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &Gc) -> bool

This method tests for !=.

impl Eq for Gc
[src]

impl AsRef<str> for Gc
[src]

fn as_ref(&self) -> &str

Performs the conversion.

impl AsRef<[u8]> for Gc
[src]

fn as_ref(&self) -> &[u8]

Performs the conversion.

impl Debug for Gc
[src]

fn fmt(&self, fmt: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Display for Gc
[src]

fn fmt(&self, fmt: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<'a> PartialEq<&'a Gc> for Gc
[src]

fn eq(&self, other: &&'a Gc) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<Gc> for &'a Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl PartialEq<char> for Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl PartialEq<str> for Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<&'a str> for Gc
[src]

fn eq(&self, other: &&'a str) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl PartialEq<GcBuf> for Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl PartialEq<String> for Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<Cow<'a, Gc>> for Gc
[src]

fn eq(&self, other: &Cow<'a, Gc>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<char> for &'a Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<str> for &'a Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<GcBuf> for &'a Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<String> for &'a Gc
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<Cow<'a, Gc>> for &'a Gc
[src]

fn eq(&self, other: &Cow<'a, Gc>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialOrd<&'a Gc> for Gc
[src]

fn partial_cmp(&self, other: &&'a Gc) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<Gc> for &'a Gc
[src]

fn partial_cmp(&self, other: &Gc) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<char> for Gc
[src]

fn partial_cmp(&self, other: &char) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<str> for Gc
[src]

fn partial_cmp(&self, other: &str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<&'a str> for Gc
[src]

fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<GcBuf> for Gc
[src]

fn partial_cmp(&self, other: &GcBuf) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<String> for Gc
[src]

fn partial_cmp(&self, other: &String) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<Cow<'a, Gc>> for Gc
[src]

fn partial_cmp(&self, other: &Cow<'a, Gc>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<char> for &'a Gc
[src]

fn partial_cmp(&self, other: &char) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<str> for &'a Gc
[src]

fn partial_cmp(&self, other: &str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<GcBuf> for &'a Gc
[src]

fn partial_cmp(&self, other: &GcBuf) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<String> for &'a Gc
[src]

fn partial_cmp(&self, other: &String) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialOrd<Cow<'a, Gc>> for &'a Gc
[src]

fn partial_cmp(&self, other: &Cow<'a, Gc>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl ToOwned for Gc
[src]

type Owned = GcBuf

fn to_owned(&self) -> Self::Owned

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