Struct janetrs::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

source

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.

source

pub unsafe fn from_raw(raw: *mut c_void) -> Self

Creates a JanetAbstract from a raw pointer

§Safety

This function doesn’t check anything.

source

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.

source

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.

source

pub fn is<A: IsJanetAbstract>(&self) -> bool

Check if the JanetAbstract data is of the type A.

source

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.

source

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.

source

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.

source

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.

source

pub const fn as_raw(&self) -> *const c_void

Acquires the underlying pointer as const pointer.

source

pub fn as_mut_raw(&mut self) -> *mut c_void

Acquires the underlying pointer.

source

pub fn cast<U: IsJanetAbstract>(self) -> *mut U

Casts to a pointer of another type.

source

pub fn size(&self) -> usize

Return the size of the type it holds.

source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<JanetAbstract> for Janet

source§

fn from(val: JanetAbstract) -> Self

Converts to this type from the input type.
source§

impl From<JanetFile> for JanetAbstract

source§

fn from(value: JanetFile) -> Self

Converts to this type from the input type.
source§

impl From<JanetRng> for JanetAbstract

source§

fn from(value: JanetRng) -> Self

Converts to this type from the input type.
source§

impl JanetTypeName for JanetAbstract

source§

fn name() -> String

Returns a string with the name of the type
source§

impl Ord for JanetAbstract

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for JanetAbstract

source§

fn eq(&self, other: &JanetAbstract) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for JanetAbstract

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Janet> for JanetAbstract

§

type Error = JanetConversionError

The type returned in the event of a conversion error.
source§

fn try_from(value: Janet) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for JanetAbstract

source§

impl StructuralPartialEq for JanetAbstract

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.