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]

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.

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.

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

Returns None if the given string was empty.

Returns the length of this grapheme cluster in bytes.

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.

Converts this to a byte slice.

Converts this to a string slice.

Returns the "base" code point.

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

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.

Returns the combining marks as a string slice.

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

An iterator over the code points of this grapheme cluster.

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

An iterator over the bytes of this grapheme cluster.

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

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

Trait Implementations

impl Eq for Gc
[src]

impl PartialEq for Gc
[src]

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

This method tests for !=.

impl Ord for Gc
[src]

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

impl PartialOrd for Gc
[src]

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

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

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

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

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

impl Hash for Gc
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl AsRef<str> for Gc
[src]

Performs the conversion.

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

Performs the conversion.

impl Debug for Gc
[src]

Formats the value using the given formatter.

impl Display for Gc
[src]

Formats the value using the given formatter. Read more

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

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

This method tests for !=.

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

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

This method tests for !=.

impl PartialEq<char> for Gc
[src]

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

This method tests for !=.

impl PartialEq<str> for Gc
[src]

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

This method tests for !=.

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

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

This method tests for !=.

impl PartialEq<GcBuf> for Gc
[src]

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

This method tests for !=.

impl PartialEq<String> for Gc
[src]

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

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

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

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

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

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

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]

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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