Rename `LuaString::get` to `to_str`
This is what similar types in libstd do (`CStr::to_str`, `OsStr::to_str`, `Path::to_str`).
This commit is contained in:
parent
a47a6e32ef
commit
16ae4720d6
|
@ -143,7 +143,7 @@ impl<'lua> ToLua<'lua> for String {
|
||||||
|
|
||||||
impl<'lua> FromLua<'lua> for String {
|
impl<'lua> FromLua<'lua> for String {
|
||||||
fn from_lua(value: LuaValue<'lua>, lua: &'lua Lua) -> LuaResult<Self> {
|
fn from_lua(value: LuaValue<'lua>, lua: &'lua Lua) -> LuaResult<Self> {
|
||||||
Ok(lua.coerce_string(value)?.get()?.to_owned())
|
Ok(lua.coerce_string(value)?.to_str()?.to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ pub struct LuaString<'lua>(LuaRef<'lua>);
|
||||||
|
|
||||||
impl<'lua> LuaString<'lua> {
|
impl<'lua> LuaString<'lua> {
|
||||||
/// Get a `&str` slice if the Lua string is valid UTF-8.
|
/// Get a `&str` slice if the Lua string is valid UTF-8.
|
||||||
pub fn get(&self) -> LuaResult<&str> {
|
pub fn to_str(&self) -> LuaResult<&str> {
|
||||||
let lua = self.0.lua;
|
let lua = self.0.lua;
|
||||||
unsafe {
|
unsafe {
|
||||||
stack_guard(lua.state, 0, || {
|
stack_guard(lua.state, 0, || {
|
||||||
|
|
|
@ -269,7 +269,7 @@ fn test_metamethods() {
|
||||||
});
|
});
|
||||||
methods.add_meta_method(LuaMetaMethod::Index, |lua, data, args| {
|
methods.add_meta_method(LuaMetaMethod::Index, |lua, data, args| {
|
||||||
let index = lua.unpack::<LuaString>(args)?;
|
let index = lua.unpack::<LuaString>(args)?;
|
||||||
if index.get()? == "inner" {
|
if index.to_str()? == "inner" {
|
||||||
lua.pack(data.0)
|
lua.pack(data.0)
|
||||||
} else {
|
} else {
|
||||||
Err("no such custom index".into())
|
Err("no such custom index".into())
|
||||||
|
|
Loading…
Reference in New Issue