Struct rlua::String

source ·
pub struct String<'lua>(_);
Expand description

Handle to an internal Lua string.

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

Implementations§

source§

impl<'lua> String<'lua>

source

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());
source

pub fn as_bytes(&self) -> &[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"[..]);
source

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

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

Trait Implementations§

source§

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

source§

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

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'lua> Clone for String<'lua>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'lua> Debug for String<'lua>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'lua> FromLua<'lua> for String<'lua>

source§

fn from_lua(value: Value<'lua>, lua: Context<'lua>) -> Result<String<'lua>>

Performs the conversion.
source§

impl<'lua> Hash for String<'lua>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'lua> ToLua<'lua> for String<'lua>

source§

fn to_lua(self, _: Context<'lua>) -> Result<Value<'lua>>

Performs the conversion.
source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'lua, T> FromLuaMulti<'lua> for Twhere T: FromLua<'lua>,

source§

fn from_lua_multi( values: MultiValue<'lua>, lua: Context<'lua> ) -> Result<T, Error>

Performs the conversion. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<'lua, T> ToLuaMulti<'lua> for Twhere T: ToLua<'lua>,

source§

fn to_lua_multi(self, lua: Context<'lua>) -> Result<MultiValue<'lua>, Error>

Performs the conversion.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.