Module bumpalo::collections::string
source · Expand description
A UTF-8 encoded, growable string.
This module contains the String
type and several error types that may
result from working with String
s.
This module is a fork of the std::string
module, that uses a bump allocator.
Examples
You can create a new String
from a string literal with String::from_str_in
:
use bumpalo::{Bump, collections::String};
let b = Bump::new();
let s = String::from_str_in("world", &b);
If you have a vector of valid UTF-8 bytes, you can make a String
out of
it. You can do the reverse too.
use bumpalo::{Bump, collections::String};
let b = Bump::new();
let sparkle_heart = bumpalo::vec![in &b; 240, 159, 146, 150];
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
assert_eq!("💖", sparkle_heart);
let bytes = sparkle_heart.into_bytes();
assert_eq!(bytes, [240, 159, 146, 150]);
Structs
- A draining iterator for
String
. - A possible error value when converting a
String
from a UTF-8 byte vector. - A possible error value when converting a
String
from a UTF-16 byte slice. - A UTF-8 encoded, growable string.