pub struct LuaString<'lua>(_);
Expand description
Handle to an internal Lua string.
Unlike Rust strings, Lua strings may not be valid UTF-8.
Implementations
sourceimpl<'lua> String<'lua>
impl<'lua> String<'lua>
sourcepub fn to_str(&self) -> Result<&str>
pub fn to_str(&self) -> Result<&str>
Get a &str
slice if the Lua string is valid UTF-8.
Examples
let globals = lua_context.globals();
let version: String = globals.get("_VERSION")?;
assert!(version.to_str().unwrap().contains("Lua"));
let non_utf8: String = lua_context.load(r#" "test\255" "#).eval()?;
assert!(non_utf8.to_str().is_err());
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get the bytes that make up this string.
The returned slice will not contain the terminating nul byte, but will contain any nul bytes embedded into the Lua string.
Examples
let non_utf8: String = lua_context.load(r#" "test\255" "#).eval()?;
assert!(non_utf8.to_str().is_err()); // oh no :(
assert_eq!(non_utf8.as_bytes(), &b"test\xff"[..]);
Trait Implementations
impl<'lua> Eq for String<'lua>
Auto Trait Implementations
impl<'lua> !RefUnwindSafe for String<'lua>
impl<'lua> !Send for String<'lua>
impl<'lua> !Sync for String<'lua>
impl<'lua> Unpin for String<'lua>
impl<'lua> !UnwindSafe for String<'lua>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more