pub struct CharList { /* private fields */ }
Expand description

An efficient string type with the same API as a linked-list of characters.

Specifically, a CharList supports the following two methods:

  1. cons which immutably prepends a character, and
  2. car_cdr which immutably splits self into its first character and everything except the first character.

Implementations

Creates an empty CharList.

Example
let empty = CharList::new();
assert!(empty.len() == 0);

Returns the length of self.

This length is in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the string.

Examples

Basic usage:

let foo = CharList::from("foo");
assert!(foo.len() == 3);

let fancy_foo = CharList::from("ƒoo"); // fancy f!
assert!(fancy_foo.len() == 4);
assert!(fancy_foo.chars().count() == 3);

Creates a new CharList which is a copy of self, but with the given character added onto the front.

Example
let lick = CharList::from("lick");
let slick = lick.cons('s');
assert!(slick == "slick");

Creates a new CharList which is a copy of self, but with the contents of the given &str added onto the front.

Example
let tonic = CharList::from("tonic");
let uh_oh = tonic.cons_str("cata");
assert!(uh_oh == "catatonic");

Returns a pair containing the first character of self and a CharList made up of everything after the first character of self.

Returns None if self is empty.

Example
let (g, oats) = CharList::from("goats").car_cdr().unwrap();
assert!((g, oats) == ('g', CharList::from("oats")));

let empty = CharList::new();
assert!(empty.car_cdr() == None);

Extracts a string slice which references self’s entire view of the underlying text.

Safety

See str::from_utf8_unchecked for safety requirements.

Returns an optional CharList representing self if prefix had been removed from the front.

let creepy_book = CharList::from("necronomicon");
let informational_book = creepy_book.without_prefix("necro");
assert!(informational_book == Some(CharList::from("nomicon")));

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.
Converts to this type from the input type.

Given an iterator over the &str "abc", the CharList "abc" will be created.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.