[][src]Struct mlua::String

pub struct String<'lua>(_);

Handle to an internal Lua string.

Unlike Rust strings, Lua strings may not be valid UTF-8.

Methods

impl<'lua> String<'lua>[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]

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"[..]);

pub fn as_bytes_with_nul(&self) -> &[u8][src]

Get the bytes that make up this string, including the trailing nul byte.

Trait Implementations

impl<'lua> AsRef<[u8]> for String<'lua>[src]

impl<'lua> Clone for String<'lua>[src]

impl<'lua> Debug for String<'lua>[src]

impl<'lua> FromLua<'lua> for String<'lua>[src]

impl<'lua, T> PartialEq<T> for String<'lua> where
    T: AsRef<[u8]>, 
[src]

impl<'lua> ToLua<'lua> for String<'lua>[src]

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> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.