From 54464b08423b60ad753d15b8f6fc2948f7edde20 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 02:11:17 +0200 Subject: [PATCH] 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(