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]

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]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [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]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [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]

fn as_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Performs the conversion.

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

fn clone(&self) -> String<'lua>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<String<'lua>>[src]

Performs the conversion.

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

fn eq(&self, other: &T) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

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

fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>>[src]

Performs the conversion.

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

pub fn erased_serialize(
    &self,
    serializer: &mut dyn Serializer
) -> Result<Ok, Error>
[src]

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

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.