Module rune_alloc::string
source · Expand description
A UTF-8–encoded, growable string.
This module contains the String type, the TryToString trait for
converting to strings, and several error types that may result from working
with Strings.
§Examples
There are multiple ways to create a new String from a string literal:
use rune::alloc::String;
use rune::alloc::prelude::*;
let s = "Hello".try_to_string()?;
let s = String::try_from("world")?;
let s: String = "also this".try_into()?;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 rune::alloc::{try_vec, String};
use rune::alloc::prelude::*;
let sparkle_heart = try_vec![240, 159, 146, 150];
let sparkle_heart = String::from_utf8(sparkle_heart)?;
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
Stringfrom a UTF-8 byte vector. - A UTF-8–encoded, growable string.
Traits§
- A trait for converting a value to a
String.