pub struct LuaString(/* private fields */);Expand description
Handle to an internal Lua string.
Unlike Rust strings, Lua strings may not be valid UTF-8.
Implementations§
Source§impl LuaString
impl LuaString
Sourcepub fn to_str(&self) -> Result<BorrowedStr>
pub fn to_str(&self) -> Result<BorrowedStr>
Get a BorrowedStr if the Lua string is valid UTF-8.
The returned BorrowedStr holds a strong reference to the Lua state to guarantee the
validity of the underlying data.
§Examples
let globals = lua.globals();
let version: LuaString = globals.get("_VERSION")?;
assert!(version.to_str()?.contains("Lua"));
let non_utf8: LuaString = lua.load(r#" "test\255" "#).eval()?;
assert!(non_utf8.to_str().is_err());Sourcepub fn to_string_lossy(&self) -> String
pub fn to_string_lossy(&self) -> String
Converts this Lua string to a String.
Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
This method returns String instead of Cow<'_, str> because lifetime cannot be
bound to a weak Lua object.
§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) -> BorrowedBytes
pub fn as_bytes(&self) -> BorrowedBytes
Get the bytes that make up this string.
The returned BorrowedStr holds a strong reference to the Lua state to guarantee the
validity of the underlying data. The data will not contain the terminating null byte, but
will contain any null bytes embedded into the Lua string.
§Examples
let non_utf8: LuaString = 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) -> BorrowedBytes
pub fn as_bytes_with_nul(&self) -> BorrowedBytes
Get the bytes that make up this string, including the trailing null byte.
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts this Lua 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§
Source§impl From<&LuaString> for BorrowedBytes
impl From<&LuaString> for BorrowedBytes
Source§impl Ord for LuaString
impl Ord for LuaString
Source§impl<T> PartialOrd<T> for LuaString
impl<T> PartialOrd<T> for LuaString
Source§impl PartialOrd for LuaString
impl PartialOrd for LuaString
Source§impl TryFrom<&LuaString> for BorrowedStr
impl TryFrom<&LuaString> for BorrowedStr
impl Eq for LuaString
Auto Trait Implementations§
impl Freeze for LuaString
impl !RefUnwindSafe for LuaString
impl Send for LuaString
impl Sync for LuaString
impl Unpin for LuaString
impl UnsafeUnpin for LuaString
impl !UnwindSafe for LuaString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
Source§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more