Type Definition generic_str::String32[][src]

pub type String32<A = Global> = OwnedString<char, Box<[MaybeUninit<char>], A>>;
Expand description

UTF-32 Owned String that supports reallocation

let mut s = String32::new();
s.push_str32(&String32::from("foobar"));
assert_eq!(s, String32::from("foobar"));

Implementations

Creates a new empty String32.

Given that the String32 is empty, this will not allocate any initial buffer. While that means that this initial operation is very inexpensive, it may cause excessive allocation later when you add data. If you have an idea of how much data the String32 will hold, consider the with_capacity method to prevent excessive re-allocation.

Examples

Basic usage:

let s = String32::new();

Creates a new empty String with a particular capacity.

Strings have an internal buffer to hold their data. The capacity is the length of that buffer, and can be queried with the capacity method. This method creates an empty String, but one with an initial buffer that can hold capacity bytes. This is useful when you may be appending a bunch of data to the String, reducing the number of reallocations it needs to do.

If the given capacity is 0, no allocation will occur, and this method is identical to the new method.

Examples

Basic usage:

let mut s = String32::with_capacity(10);

// The String contains no chars, even though it has capacity for more
assert_eq!(s.len(), 0);

// These are all done without reallocating...
let cap = s.capacity();
for _ in 0..10 {
    s.push('a');
}

assert_eq!(s.capacity(), cap);

// ...but this may make the string reallocate
s.push('a');

Trait Implementations

Performs the conversion.

Creates a value from an iterator. Read more