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, Error>
pub fn to_str(&self) -> Result<&str, Error>
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());
sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Converts this string to a Cow<str>
.
Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER
.
Examples
let lua = Lua::new();
let s = lua.create_string(b"test\xff")?;
assert_eq!(s.to_string_lossy(), "test\u{fffd}");
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.load(r#" "test\255" "#).eval()?;
assert!(non_utf8.to_str().is_err()); // oh no :(
assert_eq!(non_utf8.as_bytes(), &b"test\xff"[..]);
sourcepub fn as_bytes_with_nul(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
pub fn as_bytes_with_nul(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Get the bytes that make up this string, including the trailing nul byte.
sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts the string to a generic C pointer.
There is no way to convert the pointer back to its original value.
Typically this function is used only for hashing and debug information.
Trait Implementations
sourceimpl<'lua, T> PartialEq<T> for String<'lua>where
T: AsRef<[u8]>,
impl<'lua, T> PartialEq<T> for String<'lua>where
T: AsRef<[u8]>,
sourceimpl<'lua> Serialize for String<'lua>
impl<'lua> Serialize for String<'lua>
sourcefn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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
sourceimpl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
impl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
sourcefn from_lua_multi(values: MultiValue<'lua>, lua: &'lua Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue<'lua>, lua: &'lua Lua) -> Result<T, Error>
Performs the conversion. Read more
sourceimpl<T> Serialize for Twhere
T: Serialize + ?Sized,
impl<T> Serialize for Twhere
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
sourceimpl<'lua, T> ToLuaMulti<'lua> for Twhere
T: ToLua<'lua>,
impl<'lua, T> ToLuaMulti<'lua> for Twhere
T: ToLua<'lua>,
sourcefn to_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>, Error>
fn to_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>, Error>
Performs the conversion.