Struct bones_schema::ptr::SchemaBox

source ·
pub struct SchemaBox { /* private fields */ }
Expand description

A owning, type-erased Box-like container for types with a Schema.

Implementations§

source§

impl SchemaBox

source

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

Get a raw pointer to the box data.

source

pub fn cast_into<T: HasSchema>(self) -> T

Cast this box to it’s inner type and return it.

§Panics

Panics if the schema of the box does not match that of the type you are casting to.

source

pub fn try_cast_into<T: HasSchema>(self) -> Result<T, SchemaMismatchError>

Cast this box to it’s inner type and return it.

§Errors

Errors if the schema of the box does not match that of the type you are casting to.

source

pub unsafe fn cast_into_unchecked<T: HasSchema>(self) -> T

Unsafely convert this box into an owned T.

§Safety
  • The schema of type T must equal that of this box.
source

pub fn cast_ref<T: HasSchema>(&self) -> &T

Cast this box to a reference to a type with a representative Schema.

§Panics

Panics if the schema of the box does not match that of the type you are casting to.

source

pub fn try_cast_ref<T: HasSchema>(&self) -> Result<&T, SchemaMismatchError>

Cast this box to a reference to a type with a representative Schema.

§Errors

Errors if the schema of the box does not match that of the type you are casting to.

source

pub fn cast_mut<T: HasSchema>(&mut self) -> &mut T

Cast this box to a mutable reference to a type with a representing Schema.

§Panics

Panics if the schema of the box does not match that of the type you are casting to.

source

pub fn try_cast_mut<T: HasSchema>( &mut self, ) -> Result<&mut T, SchemaMismatchError>

Cast this box to a mutable reference to a type with a representing Schema.

§Errors

Errors if the schema of the box does not match that of the type you are casting to.

source

pub fn as_ref(&self) -> SchemaRef<'_>

Borrow this box as a SchemaRef.

source

pub fn as_mut(&mut self) -> SchemaRefMut<'_>

Borrow this box as a SchemaRefMut.

source

pub fn new<T: HasSchema + Sync + Send>(v: T) -> Self

Create a new SchemaBox from an owned type.

source

pub unsafe fn uninitialized(schema: &'static Schema) -> Self

Allocates a SchemaBox for the given Schema, but doesn’t initialize the memory.

§Safety

Accessing the data in an unitinialized SchemaBox is undefined behavior. It is up to the user to initialize the memory pointed at by the box after creating it.

source

pub fn default(schema: &'static Schema) -> Self

Create a new SchemaBox for a type with a Schema that has a SchemaData::default_fn.

§Panics

Panics if the passed in schema doesn’t have a default_fn.

source

pub fn into_sbox<T: HasSchema>(self) -> SBox<T>

Convert into an SBox if the schema of T matches.

§Panics

Panics if the schema of T doesn’t match that of the box.

source

pub fn try_into_sbox<T: HasSchema>(self) -> Result<SBox<T>, Self>

Convert into an SBox if the schema of T matches.

§Errors

Returns an error with the orignal SchemaBox if the schema of T doesn’t match.

source

pub fn schema(&self) -> &'static Schema

Get the Schema for the pointer.

source

pub unsafe fn from_raw_parts( ptr: NonNull<c_void>, schema: &'static Schema, ) -> Self

Create a new SchemaBox from raw parts.

This is useful for creating a SchemaBox for data with a schema loaded at runtime and without a Rust type.

§Safety
  • You must insure that the pointer is valid for the given schema.
source

pub fn forget(self)

Deallocate the memory stored in the box, but don’t run the destructor.

source

pub fn try_hash(&self) -> Option<u64>

Get the hash of this schema box, if supported.

source

pub fn hash(&self) -> u64

Get the hash of this schema box.

§Panics

Panics if the schema doesn’t implement hash.

Trait Implementations§

source§

impl Clone for SchemaBox

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SchemaBox

source§

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

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

impl Default for SchemaBox

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for SchemaBox

source§

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

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

impl Drop for SchemaBox

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: HasSchema> From<SBox<T>> for SchemaBox

source§

fn from(value: SBox<T>) -> Self

Converts to this type from the input type.
source§

impl HasSchema for SchemaBox

source§

fn schema() -> &'static Schema

Get this type’s Schema.
source§

fn register_schema()

Register this schema with the global schema registry. Read more
source§

fn cast<T: HasSchema>(this: &Self) -> &T

Cast a reference of this type to a reference of another type with the same memory layout. Read more
source§

fn try_cast<T: HasSchema>(this: &Self) -> Result<&T, SchemaMismatchError>

Cast a reference of this type to a reference of another type with the same memory layout. Read more
source§

fn cast_mut<T: HasSchema>(this: &mut Self) -> &mut T

Cast a mutable reference of this type to a reference of another type with the same memory layout. Read more
source§

fn try_cast_mut<T: HasSchema>( this: &mut Self, ) -> Result<&mut T, SchemaMismatchError>

Cast a mutable reference of this type to a reference of another type with the same memory layout. Read more
source§

fn as_schema_ref(&self) -> SchemaRef<'_>
where Self: Sized,

Converts a reference of T to a SchemaRef
source§

fn as_schema_mut(&mut self) -> SchemaRefMut<'_>
where Self: Sized,

Converts a reference of T to a SchemaRefMut
source§

impl Hash for SchemaBox

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for SchemaBox

source§

fn eq(&self, other: &Self) -> 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<T: HasSchema> TryFrom<SchemaBox> for SBox<T>

§

type Error = SchemaBox

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

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

Performs the conversion.
source§

impl Eq for SchemaBox

source§

impl Send for SchemaBox

source§

impl Sync for SchemaBox

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> RawClone for T
where T: Clone,

source§

unsafe fn raw_clone(src: *const c_void, dst: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_clone_cb() -> Unsafe<&'static (dyn Fn(*const c_void, *mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawDefault for T
where T: Default,

source§

unsafe fn raw_default(dst: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_default_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawDrop for T

source§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawEq for T
where T: Eq,

source§

unsafe fn raw_eq(a: *const c_void, b: *const c_void) -> bool

Get the hash of the type. Read more
source§

fn raw_eq_cb() -> Unsafe<&'static (dyn Fn(*const c_void, *const c_void) -> bool + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawHash for T
where T: Hash,

source§

unsafe fn raw_hash(ptr: *const c_void) -> u64

Get the hash of the type. Read more
source§

fn raw_hash_cb() -> Unsafe<&'static (dyn Fn(*const c_void) -> u64 + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V