pub struct String(/* private fields */);
Expand description
Handle to an internal Lua string.
Unlike Rust strings, Lua strings may not be valid UTF-8.
Implementations§
Source§impl String
impl String
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.
§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) -> StdString
pub fn to_string_lossy(&self) -> StdString
Converts this string to a StdString
.
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) -> BorrowedBytes<'_>
pub fn as_bytes(&self) -> BorrowedBytes<'_>
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) -> BorrowedBytes<'_>
pub fn as_bytes_with_nul(&self) -> BorrowedBytes<'_>
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 this 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§
impl Eq for String
Auto Trait Implementations§
impl Freeze for String
impl !RefUnwindSafe for String
impl Send for String
impl Sync for String
impl Unpin for String
impl !UnwindSafe for String
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
Mutably borrows from an owned value. Read more
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>
Performs the conversion. Read more
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> IntoLuaMulti for Twhere
T: IntoLua,
impl<T> IntoLuaMulti for Twhere
T: IntoLua,
Source§fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
Performs the conversion.