From 9b809a81976be8f69c17e86fd0834049607f5294 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 Jul 2017 23:45:24 +0200 Subject: [PATCH 1/9] Make examples adhere to API guidelines > Examples use ?, not try!, not unwrap (C-QUESTION-MARK) > Like it or not, example code is often copied verbatim by users. > Unwrapping an error should be a conscious decision that the user > needs to make. --- src/lua.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 8fee6b5..7e8d896 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -176,16 +176,20 @@ impl<'lua> String<'lua> { /// /// ``` /// # extern crate rlua; - /// # use rlua::{Lua, String}; - /// # fn main() { + /// # use rlua::{Lua, String, Result}; + /// # fn try_main() -> Result<()> { /// let lua = Lua::new(); /// let globals = lua.globals(); /// - /// let version: String = globals.get("_VERSION").unwrap(); + /// let version: String = globals.get("_VERSION")?; /// assert!(version.to_str().unwrap().contains("Lua")); /// - /// let non_utf8: String = lua.eval(r#" "test\xff" "#, None).unwrap(); + /// let non_utf8: String = lua.eval(r#" "test\xff" "#, None)?; /// assert!(non_utf8.to_str().is_err()); + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); /// # } /// ``` pub fn to_str(&self) -> Result<&str> { @@ -509,19 +513,22 @@ impl<'lua> Function<'lua> { /// /// ``` /// # extern crate rlua; - /// # use rlua::{Lua, Function}; - /// - /// # fn main() { + /// # use rlua::{Lua, Function, Result}; + /// # fn try_main() -> Result<()> { /// let lua = Lua::new(); /// let globals = lua.globals(); /// /// // Bind the argument `123` to Lua's `tostring` function - /// let tostring: Function = globals.get("tostring").unwrap(); - /// let tostring_123: Function = tostring.bind(123i32).unwrap(); + /// let tostring: Function = globals.get("tostring")?; + /// let tostring_123: Function = tostring.bind(123i32)?; /// /// // Now we can call `tostring_123` without arguments to get the result of `tostring(123)` - /// let result: String = tostring_123.call(()).unwrap(); + /// let result: String = tostring_123.call(())?; /// assert_eq!(result, "123"); + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); /// # } /// ``` pub fn bind>(&self, args: A) -> Result> { @@ -603,9 +610,8 @@ impl<'lua> Thread<'lua> { /// /// ``` /// # extern crate rlua; - /// # use rlua::*; - /// - /// # fn main() { + /// # use rlua::{Lua, Thread, Error, Result}; + /// # fn try_main() -> Result<()> { /// let lua = Lua::new(); /// let thread: Thread = lua.eval(r#" /// coroutine.create(function(arg) @@ -624,6 +630,10 @@ impl<'lua> Thread<'lua> { /// Err(Error::CoroutineInactive) => {}, /// unexpected => panic!("unexpected result {:?}", unexpected), /// } + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); /// # } /// ``` pub fn resume(&self, args: A) -> Result From 63e0587d2665fd2abc732f0c55e89868f3a8a2d4 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 Jul 2017 23:52:15 +0200 Subject: [PATCH 2/9] Remove "equivalent" Lua code from Function::bind Not only was this code not equivalent, it didn't even run since varargs cannot be used as an upvalue (it's multiple values, after all). Since Lua does not allow passing 2 sets of variadic arguments to a function, the resulting code would be *very* complex and would involve packing both sets of varargs into tables, concatenating them, then `table.unpack`ing them to finally pass them. This complex code would only make the docs more difficult to understand, which is the opposite effect I originally intended with this. Let's just get rid of this bad equivalence. --- src/lua.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 7e8d896..148c3d9 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -501,14 +501,6 @@ impl<'lua> Function<'lua> { /// Returns a function that, when called with no arguments, calls `self`, passing `args` as /// arguments. /// - /// This is equivalent to this Lua code: - /// - /// ```notrust - /// function bind(f, ...) - /// return function() f(...) end - /// end - /// ``` - /// /// # Example /// /// ``` From 59ab95f6ffd4d9f2eaf6de462230a7c07430658a Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 00:05:36 +0200 Subject: [PATCH 3/9] Beef up Function::bind docs + example --- src/lua.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 148c3d9..0370b6b 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -498,9 +498,11 @@ impl<'lua> Function<'lua> { } } - /// Returns a function that, when called with no arguments, calls `self`, passing `args` as + /// Returns a function that, when called, calls `self`, passing `args` as the first set of /// arguments. /// + /// If any arguments are passed to the returned function, they will be passed after `args`. + /// /// # Example /// /// ``` @@ -508,15 +510,19 @@ impl<'lua> Function<'lua> { /// # use rlua::{Lua, Function, Result}; /// # fn try_main() -> Result<()> { /// let lua = Lua::new(); - /// let globals = lua.globals(); /// - /// // Bind the argument `123` to Lua's `tostring` function - /// let tostring: Function = globals.get("tostring")?; - /// let tostring_123: Function = tostring.bind(123i32)?; + /// let sum: Function = lua.eval(r#" + /// function(a, b) + /// return a + b + /// end + /// "#, None)?; + /// + /// let bound_a = sum.bind(1)?; + /// assert_eq!(bound_a.call::<_, u32>(2)?, 1 + 2); + /// + /// let bound_a_and_b = sum.bind(13)?.bind(57)?; + /// assert_eq!(bound_a_and_b.call::<_, u32>(())?, 13 + 57); /// - /// // Now we can call `tostring_123` without arguments to get the result of `tostring(123)` - /// let result: String = tostring_123.call(())?; - /// assert_eq!(result, "123"); /// # Ok(()) /// # } /// # fn main() { From 0b7b7e9d79618ac95645b491321626a808af8f15 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 00:16:43 +0200 Subject: [PATCH 4/9] Add Function::call example --- src/lua.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 0370b6b..2be45fc 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -172,7 +172,7 @@ pub struct String<'lua>(LuaRef<'lua>); impl<'lua> String<'lua> { /// Get a `&str` slice if the Lua string is valid UTF-8. /// - /// # Example + /// # Examples /// /// ``` /// # extern crate rlua; @@ -471,6 +471,52 @@ impl<'lua> Function<'lua> { /// Calls the function, passing `args` as function arguments. /// /// The function's return values are converted to the generic type `R`. + /// + /// # Examples + /// + /// Call Lua's built-in `tostring` function: + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, Function, Result}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// let globals = lua.globals(); + /// + /// let tostring: Function = globals.get("tostring")?; + /// + /// assert_eq!(tostring.call::<_, String>(123)?, "123"); + /// + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` + /// + /// Call a function with multiple arguments: + /// + /// ``` + /// # extern crate rlua; + /// # #[macro_use] extern crate hlist_macro; + /// # use rlua::{Lua, Function, Result}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// + /// let sum: Function = lua.eval(r#" + /// function(a, b) + /// return a + b + /// end + /// "#, None)?; + /// + /// assert_eq!(sum.call::<_, u32>(hlist![3, 4])?, 3 + 4); + /// + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` pub fn call, R: FromLuaMulti<'lua>>(&self, args: A) -> Result { let lua = self.0.lua; unsafe { @@ -503,7 +549,7 @@ impl<'lua> Function<'lua> { /// /// If any arguments are passed to the returned function, they will be passed after `args`. /// - /// # Example + /// # Examples /// /// ``` /// # extern crate rlua; @@ -598,13 +644,13 @@ impl<'lua> Thread<'lua> { /// are passed to its main function. /// /// If the thread is no longer in `Active` state (meaning it has finished execution or - /// encountered an error), this will return Err(CoroutineInactive), otherwise will return Ok as - /// follows: + /// encountered an error), this will return `Err(CoroutineInactive)`, otherwise will return `Ok` + /// as follows: /// /// If the thread calls `coroutine.yield`, returns the values passed to `yield`. If the thread /// `return`s values from its main function, returns those. /// - /// # Example + /// # Examples /// /// ``` /// # extern crate rlua; From e2aeca58ae204ee94c6b3bc6a711f45cd3f4dbb8 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 01:40:53 +0200 Subject: [PATCH 5/9] Table docs and examples This looks almost like the standard lib now :) --- src/lua.rs | 150 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 139 insertions(+), 11 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 2be45fc..f54f4dd 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -218,8 +218,39 @@ impl<'lua> Table<'lua> { /// /// If the value is `nil`, this will effectively remove the pair. /// - /// This might invoke the `__newindex` metamethod. Use the `raw_set` method if that is not + /// This might invoke the `__newindex` metamethod. Use the [`raw_set`] method if that is not /// desired. + /// + /// # Examples + /// + /// Export a value as a global to make it usable from Lua: + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, Result}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// let globals = lua.globals(); + /// + /// globals.set("assertions", cfg!(debug_assertions))?; + /// + /// lua.eval::<()>(r#" + /// if assertions == true then + /// -- ... + /// elseif assertions == false then + /// -- ... + /// else + /// error("assertions neither on nor off?") + /// end + /// "#, None)?; + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` + /// + /// [`raw_set`]: #method.raw_set pub fn set, V: ToLua<'lua>>(&self, key: K, value: V) -> Result<()> { let lua = self.0.lua; let key = key.to_lua(lua)?; @@ -239,7 +270,30 @@ impl<'lua> Table<'lua> { /// /// If no value is associated to `key`, returns the `nil` value. /// - /// This might invoke the `__index` metamethod. Use the `raw_get` method if that is not desired. + /// This might invoke the `__index` metamethod. Use the [`raw_get`] method if that is not + /// desired. + /// + /// # Examples + /// + /// Query the version of the Lua interpreter: + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, Result}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// let globals = lua.globals(); + /// + /// let version: String = globals.get("_VERSION")?; + /// println!("Lua version: {}", version); + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` + /// + /// [`raw_get`]: #method.raw_get pub fn get, V: FromLua<'lua>>(&self, key: K) -> Result { let lua = self.0.lua; let key = key.to_lua(lua)?; @@ -307,7 +361,9 @@ impl<'lua> Table<'lua> { /// Returns the result of the Lua `#` operator. /// - /// This might invoke the `__len` metamethod. Use the `raw_len` method if that is not desired. + /// This might invoke the `__len` metamethod. Use the [`raw_len`] method if that is not desired. + /// + /// [`raw_len`]: #method.raw_len pub fn len(&self) -> Result { let lua = self.0.lua; unsafe { @@ -335,8 +391,42 @@ impl<'lua> Table<'lua> { } } - /// Consume this table and return an iterator over the pairs of the table, works like the Lua - /// 'pairs' function. + /// Consume this table and return an iterator over the pairs of the table. + /// + /// This works like the Lua `pairs` function, but does not invoke the `__pairs` metamethod. + /// + /// The pairs are wrapped in a [`Result`], since they are lazily converted to `K` and `V` types. + /// + /// # Note + /// + /// While this method consumes the `Table` object, it can not prevent code from mutating the + /// table while the iteration is in progress. Refer to the [Lua manual] for information about + /// the consequences of such mutation. + /// + /// # Examples + /// + /// Iterate over all globals: + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, Result, Value}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// let globals = lua.globals(); + /// + /// for pair in globals.pairs::() { + /// let (key, value) = pair?; + /// // ... + /// } + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` + /// + /// [`Result`]: type.Result.html + /// [Lua manual]: http://www.lua.org/manual/5.3/manual.html#pdf-next pub fn pairs, V: FromLua<'lua>>(self) -> TablePairs<'lua, K, V> { let next_key = Some(LuaRef { lua: self.0.lua, @@ -350,9 +440,44 @@ impl<'lua> Table<'lua> { } } - /// Consume this table and return an iterator over the values of this table, which should be a - /// sequence. Works like the Lua 'ipairs' function, but doesn't return the indexes, only the - /// values in order. + /// Consume this table and return an iterator over all values in the sequence part of the table. + /// + /// The iterator will yield all values `t[1]`, `t[2]`, and so on, until a `nil` value is + /// encountered. This mirrors the behaviour of Lua's `ipairs` function and will invoke the + /// `__index` metamethod according to the usual rules. However, the deprecated `__ipairs` + /// metatable will not be called. + /// + /// Just like [`pairs`], the values are wrapped in a [`Result`]. + /// + /// # Note + /// + /// While this method consumes the `Table` object, it can not prevent code from mutating the + /// table while the iteration is in progress. Refer to the [Lua manual] for information about + /// the consequences of such mutation. + /// + /// # Examples + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, Result, Table}; + /// # fn try_main() -> Result<()> { + /// let lua = Lua::new(); + /// let my_table: Table = lua.eval("{ [1] = 4, [2] = 5, [4] = 7, key = 2 }", None)?; + /// + /// let expected = [4, 5]; + /// for (&expected, got) in expected.iter().zip(my_table.sequence_values::()) { + /// assert_eq!(expected, got?); + /// } + /// # Ok(()) + /// # } + /// # fn main() { + /// # try_main().unwrap(); + /// # } + /// ``` + /// + /// [`pairs`]: #method.pairs + /// [`Result`]: type.Result.html + /// [Lua manual]: http://www.lua.org/manual/5.3/manual.html#pdf-next pub fn sequence_values>(self) -> TableSequence<'lua, V> { TableSequence { table: self.0, @@ -364,7 +489,9 @@ impl<'lua> Table<'lua> { /// An iterator over the pairs of a Lua table. /// -/// Should behave exactly like the lua 'pairs' function. Holds an internal reference to the table. +/// This struct is created by the [`Table::pairs`] method. +/// +/// [`Table::pairs`]: struct.Table.html#method.pairs pub struct TablePairs<'lua, K, V> { table: LuaRef<'lua>, next_key: Option>, @@ -419,8 +546,9 @@ where /// An iterator over the sequence part of a Lua table. /// -/// Should behave similarly to the lua 'ipairs" function, except only produces the values, not the -/// indexes. Holds an internal reference to the table. +/// This struct is created by the [`Table::sequence_values`] method. +/// +/// [`Table::sequence_values`]: struct.Table.html#method.sequence_values pub struct TableSequence<'lua, V> { table: LuaRef<'lua>, index: Option, From 34fd4a00cea423f1240265f6bd5a1b4494d44681 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 02:00:49 +0200 Subject: [PATCH 6/9] Document UserDataMethods --- src/lua.rs | 58 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index f54f4dd..18c1491 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -926,12 +926,9 @@ pub enum MetaMethod { ToString, } -/// Stores methods of a userdata object. +/// Method registry for [`UserData`] implementors. /// -/// Methods added will be added to the `__index` table on the metatable for the userdata, so they -/// can be called as `userdata:method(args)` as expected. If there are any regular methods, and an -/// `Index` metamethod is given, it will be called as a *fallback* if the index doesn't match an -/// existing regular method. +/// [`UserData`]: trait.UserData.html pub struct UserDataMethods<'lua, T> { methods: HashMap>, meta_methods: HashMap>, @@ -939,7 +936,13 @@ pub struct UserDataMethods<'lua, T> { } impl<'lua, T: UserData> UserDataMethods<'lua, T> { - /// Add a regular method as a function which accepts a &T as the first parameter. + /// Add a method which accepts a `&T` as the first parameter. + /// + /// Regular methods are implemented by overriding the `__index` metamethod and returning the + /// accessed method. This allows them to be used with the expected `userdata:method()` syntax. + /// + /// If `add_meta_method` is used to override the `__index` metamethod, this approach will fall + /// back to the user-provided metamethod if no regular method was found. pub fn add_method(&mut self, name: &str, method: M) where M: 'lua + for<'a> FnMut(&'lua Lua, &'a T, MultiValue<'lua>) -> Result>, @@ -950,7 +953,11 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { ); } - /// Add a regular method as a function which accepts a &mut T as the first parameter. + /// Add a regular method which accepts a `&mut T` as the first parameter. + /// + /// Refer to [`add_method`] for more information about the implementation. + /// + /// [`add_method`]: #method.add_method pub fn add_method_mut(&mut self, name: &str, method: M) where M: 'lua + for<'a> FnMut(&'lua Lua, &'a mut T, MultiValue<'lua>) -> Result>, @@ -963,6 +970,11 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { /// Add a regular method as a function which accepts generic arguments, the first argument will /// always be a `UserData` of type T. + /// + /// Prefer to use [`add_method`] or [`add_method_mut`] as they are easier to use. + /// + /// [`add_method`]: #method.add_method + /// [`add_method_mut`]: #method.add_method_mut pub fn add_function(&mut self, name: &str, function: F) where F: 'lua + for<'a> FnMut(&'lua Lua, MultiValue<'lua>) -> Result>, @@ -970,9 +982,14 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { self.methods.insert(name.to_owned(), Box::new(function)); } - /// Add a metamethod as a function which accepts a &T as the first parameter. This can cause an - /// error with certain binary metamethods that can trigger if ony the right side has a - /// metatable. + /// Add a metamethod which accepts a `&T` as the first parameter. + /// + /// # Note + /// + /// This can cause an error with certain binary metamethods that can trigger if only the right + /// side has a metatable. To prevent this, use [`add_meta_function`]. + /// + /// [`add_meta_function`]: #method.add_meta_function pub fn add_meta_method(&mut self, meta: MetaMethod, method: M) where M: 'lua + for<'a> FnMut(&'lua Lua, &'a T, MultiValue<'lua>) -> Result>, @@ -980,9 +997,14 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { self.meta_methods.insert(meta, Self::box_method(method)); } - /// Add a metamethod as a function which accepts a &mut T as the first parameter. This can - /// cause an error with certain binary metamethods that can trigger if ony the right side has a - /// metatable. + /// Add a metamethod as a function which accepts a `&mut T` as the first parameter. + /// + /// # Note + /// + /// This can cause an error with certain binary metamethods that can trigger if only the right + /// side has a metatable. To prevent this, use [`add_meta_function`]. + /// + /// [`add_meta_function`]: #method.add_meta_function pub fn add_meta_method_mut(&mut self, meta: MetaMethod, method: M) where M: 'lua + for<'a> FnMut(&'lua Lua, &'a mut T, MultiValue<'lua>) -> Result>, @@ -990,10 +1012,11 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { self.meta_methods.insert(meta, Self::box_method_mut(method)); } - /// Add a metamethod as a function which accepts generic arguments. Metamethods in Lua for - /// binary operators can be triggered if either the left or right argument to the binary - /// operator has a metatable, so the first argument here is not necessarily a userdata of type - /// T. + /// Add a metamethod which accepts generic arguments. + /// + /// Metamethods for binary operators can be triggered if either the left or right argument to + /// the binary operator has a metatable, so the first argument here is not necessarily a + /// userdata of type `T`. pub fn add_meta_function(&mut self, meta: MetaMethod, function: F) where F: 'lua + for<'a> FnMut(&'lua Lua, MultiValue<'lua>) -> Result>, @@ -1015,7 +1038,6 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> { .to_owned(), )) }) - } fn box_method_mut(mut method: M) -> Callback<'lua> From 58c80c05be3064e017b9fbd21bc9b3e0c311f7d7 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 02:05:57 +0200 Subject: [PATCH 7/9] Replace unneeded eval by exec --- src/lua.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua.rs b/src/lua.rs index 18c1491..5ee74d4 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -234,7 +234,7 @@ impl<'lua> Table<'lua> { /// /// globals.set("assertions", cfg!(debug_assertions))?; /// - /// lua.eval::<()>(r#" + /// lua.exec::<()>(r#" /// if assertions == true then /// -- ... /// elseif assertions == false then From 54464b08423b60ad753d15b8f6fc2948f7edde20 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 02:11:17 +0200 Subject: [PATCH 8/9] AnyUserData docs --- src/lua.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 5ee74d4..55f0f43 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1076,19 +1076,29 @@ pub trait UserData: 'static + Sized { pub struct AnyUserData<'lua>(LuaRef<'lua>); impl<'lua> AnyUserData<'lua> { - /// Checks whether `T` is the type of this userdata. + /// Checks whether the type of this userdata is `T`. pub fn is(&self) -> bool { self.inspect(|_: &RefCell| ()).is_some() } - /// Borrow this userdata out of the internal RefCell that is held in lua. + /// Borrow this userdata immutably if it is of type `T`. + /// + /// # Errors + /// + /// Returns a `UserDataBorrowError` if the userdata is already mutably borrowed. Returns a + /// `UserDataTypeMismatch` if the userdata is not of type `T`. pub fn borrow(&self) -> Result> { self.inspect(|cell| { Ok(cell.try_borrow().map_err(|_| Error::UserDataBorrowError)?) }).ok_or(Error::UserDataTypeMismatch)? } - /// Borrow mutably this userdata out of the internal RefCell that is held in lua. + /// Borrow this userdata mutably if it is of type `T`. + /// + /// # Errors + /// + /// Returns a `UserDataBorrowMutError` if the userdata is already borrowed. Returns a + /// `UserDataTypeMismatch` if the userdata is not of type `T`. pub fn borrow_mut(&self) -> Result> { self.inspect(|cell| { Ok(cell.try_borrow_mut().map_err( From 335ecbbac633e0a5f818520c5c2375068574cf6e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 02:13:11 +0200 Subject: [PATCH 9/9] tiny typo --- src/lua.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua.rs b/src/lua.rs index 55f0f43..3853992 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1306,7 +1306,7 @@ impl Lua { .call(()) } - /// Pass a `&str` slice to Lua, creating and returning a interned Lua string. + /// Pass a `&str` slice to Lua, creating and returning an interned Lua string. pub fn create_string(&self, s: &str) -> String { unsafe { stack_guard(self.state, 0, || {