[−][src]Struct glsp::RData
The rdata
primitive type.
This is a Rust value which has been moved onto the garbage-collected heap. It can be constructed
using the glsp::rdata
function.
RData
has several convenience features:
-
It supports interior mutability, like a
RefCell
. -
It can be manually deallocated, or taken back from the garbage-collected heap, using
free
andtake
. Any attempts to access a deallocatedRData
from GameLisp will trigger an error. -
It's dynamically typed: a
Vec<Root<RData>>
could refer to several different Rust types. (If this is undesirable, consider usingRRoot
instead.) -
The
rdata!
macro enables Rust functions to be associated with anRData
as its methods and properties. They can be accessed from GameLisp code, or accessed from Rust code using an API similar toObj
.
Implementations
impl RData
[src]
pub fn type_name(&self) -> &'static str
[src]
pub fn class_name(&self) -> Sym
[src]
pub fn is<T>(&self) -> bool where
T: RStore,
[src]
T: RStore,
Returns true
if this RData
is currently storing a value of type T
.
pub fn borrow<T>(&self) -> RRef<T> where
T: RStore,
[src]
T: RStore,
Returns a shared reference to the value being stored by this RData
.
Panics if the RData
is not storing a value of type T
; if its value has been freed; or
if the value is currently mutably borrowed.
pub fn try_borrow<T>(&self) -> Result<RRef<T>, GError> where
T: RStore,
[src]
T: RStore,
Returns a shared reference to the value being stored by this RData
.
Returns an Err
if the RData
is not storing a value of type T
; if its value has
been freed; or if the value is currently mutably borrowed.
pub fn borrow_mut<T>(&self) -> RRefMut<T> where
T: RStore,
[src]
T: RStore,
Returns a mutable reference to the value being stored by this RData
.
Panics if the RData
is not storing a value of type T
; if its value has been freed; or
if the value is currently borrowed.
pub fn try_borrow_mut<T>(&self) -> Result<RRefMut<T>, GError> where
T: RStore,
[src]
T: RStore,
Returns a mutable reference to the value being stored by this RData
.
Returns an Err
if the RData
is not storing a value of type T
; if its value has
been freed; or if the value is currently borrowed.
pub fn take<T>(&self) -> Result<T, GError> where
T: RStore,
[src]
T: RStore,
Takes the value stored in this RData
and returns it.
Any future attempts to access the value will gracefully fail.
Returns an Err
if the RData
is not storing a value of type T
; if its value has already
been freed; or if it's currently borrowed.
pub fn free(&self) -> Result<(), GError>
[src]
Drops the value stored by this RData
.
Any future attempts to access the value will gracefully fail.
Returns an Err
if the RData
is not storing a value of type T
; if its value has already
been freed; or if it's currently borrowed.
pub fn is_freed(&self) -> bool
[src]
Returns true
if this RData
's value has been taken or freed.
pub fn access_giter(rdata: &Root<RData>, giter: &Root<GIter>) -> Root<GIter>
[src]
Creates an indexing iterator for this collection.
Equivalent to [rdata iter]
.
pub fn get<S, R>(&self, key: S) -> Result<R, GError> where
R: FromVal,
S: ToSym,
[src]
R: FromVal,
S: ToSym,
Accesses the value of a field or property.
Equivalent to [rdata key]
.
pub fn get_if_present<S, R>(&self, key: S) -> Result<Option<R>, GError> where
R: FromVal,
S: ToSym,
[src]
R: FromVal,
S: ToSym,
Accesses the value of a field or property, if it exists.
Equivalent to [rdata (? key)]
.
pub fn set<S, V>(&self, key: S, val: V) -> Result<(), GError> where
S: ToSym,
V: ToVal,
[src]
S: ToSym,
V: ToVal,
Mutates the field or property bound to the given name.
Equivalent to (= [rdata key] val)
.
pub fn set_if_present<S, V>(&self, key: S, val: V) -> Result<bool, GError> where
S: ToSym,
V: ToVal,
[src]
S: ToSym,
V: ToVal,
Mutates the field or property bound to the given name, if any. Returns true
if the
field or property exists.
Equivalent to (= [rdata (? key)] val)
.
pub fn call<S, A, R>(&self, key: S, args: &A) -> Result<R, GError> where
A: ToCallArgs + ?Sized,
R: FromVal,
S: ToSym,
[src]
A: ToCallArgs + ?Sized,
R: FromVal,
S: ToSym,
Invokes a method.
Equivalent to (call-meth rdata key ..args)
.
pub fn call_if_present<S, A, R>(
&self,
key: S,
args: &A
) -> Result<Option<R>, GError> where
A: ToCallArgs + ?Sized,
R: FromVal,
S: ToSym,
[src]
&self,
key: S,
args: &A
) -> Result<Option<R>, GError> where
A: ToCallArgs + ?Sized,
R: FromVal,
S: ToSym,
Invokes a method, if it exists.
Equivalent to (call-meth rdata (? key) ..args)
.
pub fn has_meth<S>(&self, key: S) -> Result<bool, GError> where
S: ToSym,
[src]
S: ToSym,
Returns true
if the given name is bound to a method.
Equivalent to (has-meth? rdata key)
.
pub fn try_eq(&self, other: &Root<RData>) -> Result<bool, GError>
[src]
Equivalent to (eq? self other)
.
Note that, because this may invoke an op-eq?
method, it can potentially fail.
The same is true for PartialEq
comparisons between RData
using Rust's ==
operator.
In that case, if an error occurs, the operator will panic.
Trait Implementations
impl Debug for RData
[src]
impl Display for RData
[src]
impl GStore for RData
[src]
impl<'a, 'r> MakeArg<'a> for &'r RData where
'a: 'r,
[src]
'a: 'r,
impl PartialEq<Root<RData>> for RData
[src]
Auto Trait Implementations
impl !GSend for RData
impl !RefUnwindSafe for RData
impl !Send for RData
impl !Sync for RData
impl Unpin for RData
impl !UnwindSafe for RData
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,