Struct mlua::String [−][src]
pub struct String<'lua>(_);
Expand description
Handle to an internal Lua string.
Unlike Rust strings, Lua strings may not be valid UTF-8.
Implementations
impl<'lua> String<'lua>
[src]
impl<'lua> String<'lua>
[src]pub fn to_str(&self) -> Result<&str>
[src]
pub fn to_str(&self) -> Result<&str>
[src]Get a &str
slice if the Lua string is valid UTF-8.
Examples
let globals = lua.globals(); let version: String = globals.get("_VERSION")?; assert!(version.to_str()?.contains("Lua")); let non_utf8: String = lua.load(r#" "test\255" "#).eval()?; assert!(non_utf8.to_str().is_err());
pub fn as_bytes(&self) -> &[u8]ⓘ
[src]
pub fn as_bytes(&self) -> &[u8]ⓘ
[src]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.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
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
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]pub fn erased_serialize(
&self,
serializer: &mut dyn Serializer
) -> Result<Ok, Error>
[src]
&self,
serializer: &mut dyn Serializer
) -> Result<Ok, Error>
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more