Struct janetrs::janet_abstract::JanetAbstract
source · pub struct JanetAbstract { /* private fields */ }
Expand description
Type that represents the Janet Abstract type.
Janet Abstract types is the way to expose non-native types to the Janet Runtime and allow the Janet user to interact with them.
It works like a *mut c_void
pointer, but the memory it uses are tracked by the Janet
Garbage Collector.
Implementations§
source§impl JanetAbstract
impl JanetAbstract
sourcepub fn new<A: IsJanetAbstract>(value: A) -> Self
pub fn new<A: IsJanetAbstract>(value: A) -> Self
Creates a JanetAbstract
using information from the type that can be used as
JanetAbstract
.
This function manually wraps the value
in a ManuallyDrop
to avoid the
value being dropped when the value
is assigned to the JanetAbstract
internal
raw pointer.
Note that IsJanetAbstract
is implemented for ManuallyDrop
of any type that
implements IsJanetAbstract
.
sourcepub unsafe fn get_unchecked<A: IsJanetAbstract>(&self) -> &A::Get
pub unsafe fn get_unchecked<A: IsJanetAbstract>(&self) -> &A::Get
Returns a reference to the abstract type data as A
§Safety
This function doesn’t check if the underlying data of the JanetAbstract
object
and the requested type A
are the same.
sourcepub unsafe fn get_mut_unchecked<A: IsJanetAbstract>(&mut self) -> &mut A::Get
pub unsafe fn get_mut_unchecked<A: IsJanetAbstract>(&mut self) -> &mut A::Get
Returns a mutable reference to the abstract type data as A
§Safety
This function doesn’t check if the underlying data of the JanetAbstract
object
and the requested type A
are the same.
sourcepub fn is<A: IsJanetAbstract>(&self) -> bool
pub fn is<A: IsJanetAbstract>(&self) -> bool
Check if the JanetAbstract
data is of the type A
.
sourcepub fn get<A: IsJanetAbstract>(&self) -> Result<&A::Get, AbstractError>
pub fn get<A: IsJanetAbstract>(&self) -> Result<&A::Get, AbstractError>
Returns a reference to value if it’s the same kind of abstract.
§Error
This function may return AbstractError::MismatchedSize
if this object size is
different of requested type A
size, AbstractError::MismatchedAbstractType
if any of the function pointer in the JanetAbstractType
are different, or
AbstractError::NullDataPointer
if the JanetAbstract is in a uninitialized
state.
sourcepub fn get_mut<A: IsJanetAbstract>(
&mut self
) -> Result<&mut A::Get, AbstractError>
pub fn get_mut<A: IsJanetAbstract>( &mut self ) -> Result<&mut A::Get, AbstractError>
Returns a exclusive reference to value if it’s the same kind of abstract.
§Error
This function may return AbstractError::MismatchedSize
if this object size is
different of requested type A
size, AbstractError::MismatchedAbstractType
if any of the function pointer in the JanetAbstractType
are different, or
AbstractError::NullDataPointer
if the JanetAbstract is in a uninitialized
state.
sourcepub fn take<A: IsJanetAbstract>(&mut self) -> Result<A, AbstractError>
pub fn take<A: IsJanetAbstract>(&mut self) -> Result<A, AbstractError>
Takes the value out of this JanetAbstract, moving it back to an uninitialized state.
§Error
This function may return AbstractError::MismatchedSize
if this object size is
different of requested type A
size, AbstractError::MismatchedAbstractType
if any of the function pointer in the JanetAbstractType
are different, or
AbstractError::NullDataPointer
if the JanetAbstract is in a uninitialized
state.
sourcepub fn into_inner<A: IsJanetAbstract>(self) -> Result<A, AbstractError>
pub fn into_inner<A: IsJanetAbstract>(self) -> Result<A, AbstractError>
Extracts the value from the ManuallyDrop container.
This allows the value to be dropped again.
§Error
This function may return AbstractError::MismatchedSize
if this object size is
different of requested type A
size, AbstractError::MismatchedAbstractType
if any of the function pointer in the JanetAbstractType
are different, or
AbstractError::NullDataPointer
if the JanetAbstract is in a uninitialized
state.
sourcepub fn as_mut_raw(&mut self) -> *mut c_void
pub fn as_mut_raw(&mut self) -> *mut c_void
Acquires the underlying pointer.
sourcepub fn cast<U: IsJanetAbstract>(self) -> *mut U
pub fn cast<U: IsJanetAbstract>(self) -> *mut U
Casts to a pointer of another type.
sourcepub fn type_info(&self) -> JanetAbstractType
pub fn type_info(&self) -> JanetAbstractType
Return the struct that holds the type name and all possible polymorphic function pointer that a Abstract type can have in Janet.
Trait Implementations§
source§impl Debug for JanetAbstract
impl Debug for JanetAbstract
source§impl From<JanetAbstract> for Janet
impl From<JanetAbstract> for Janet
source§fn from(val: JanetAbstract) -> Self
fn from(val: JanetAbstract) -> Self
source§impl From<JanetFile> for JanetAbstract
impl From<JanetFile> for JanetAbstract
source§impl From<JanetRng> for JanetAbstract
impl From<JanetRng> for JanetAbstract
source§impl JanetTypeName for JanetAbstract
impl JanetTypeName for JanetAbstract
source§impl Ord for JanetAbstract
impl Ord for JanetAbstract
source§impl PartialEq for JanetAbstract
impl PartialEq for JanetAbstract
source§fn eq(&self, other: &JanetAbstract) -> bool
fn eq(&self, other: &JanetAbstract) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for JanetAbstract
impl PartialOrd for JanetAbstract
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more