Struct TypeInfo

Source
pub struct TypeInfo {
    pub ty: TypeId,
    pub name: &'static str,
    pub size: usize,
    pub align: usize,
    pub fn_drop: FnDropRaw,
    pub is_send: bool,
    pub is_sync: bool,
    pub is_default: bool,
    pub fn_default: FnDefaultRaw,
    pub is_clone: bool,
    pub fn_clone: FnCloneRaw,
}
Expand description

Type information such as TypeId, name, size, and alignment.

Also, the struct contains additional information shown below.

  • Type erased drop function.
  • Whether the type is Send or not.
  • Whether the type is Sync or not.
  • Whether the type is Clone or not and type erased clone function.
  • Whether the type is Default or not and type erased default function.

It’s highly encouraged to use tinfo macro to construct this struct to avoid incorrect construction.

§Examples

use my_ecs::tinfo;

let x = tinfo!(i32);
assert!(x.is_send && x.is_sync && x.is_default && x.is_clone);

let x = tinfo!(std::rc::Rc<i32>);
assert!(!x.is_send && !x.is_sync && x.is_default && x.is_clone);

Fields§

§ty: TypeId

Type id.

§name: &'static str

Type name.

This field may differ from rust version to version.

§size: usize

Type size in bytes.

Size must be a multiple of align including zero.

§align: usize

Type alignment in bytes.

Alignment must be a power of two, at lease one.

§fn_drop: FnDropRaw

Raw Drop::drop function pointer for the item type.

§is_send: bool

Whether the type is Send or not.

§is_sync: bool

Whether the type is Sync or not.

§is_default: bool

Whether the type is Default or not.

§fn_default: FnDefaultRaw

Raw Default::default function pointer for the item type.

If the item type is not Default, calling this function causes panic.

§is_clone: bool

Whether the type is Clone or not.

§fn_clone: FnCloneRaw

Raw Clone::clone function pointer for the item type.

If the item type is not Clone, calling this function causes panic.

Implementations§

Source§

impl TypeInfo

Source

pub fn new<T: 'static>( is_send: bool, is_sync: bool, fn_default: Option<FnDefaultRaw>, fn_clone: Option<FnCloneRaw>, ) -> Self

Creates a TypeInfo for the given type.

§Examples
use my_ecs::ds::{TypeInfo, TypeHelper};

#[derive(Clone)]
struct X;

// Creates `TypeInfo` for the `X`.
let is_send = true;
let is_sync = true;
let fn_default = None;
let fn_clone = Some(TypeHelper::<X>::FN_CLONE);
let info = TypeInfo::new::<X>(is_send, is_sync, fn_default, fn_clone);
Source

pub fn is_type_of<T: 'static>(&self) -> bool

Returns true if the type information is about the given type.

§Examples
use my_ecs::prelude::*;

let tinfo = tinfo!(i32);
assert!(tinfo.is_type_of::<i32>());

Trait Implementations§

Source§

impl Clone for TypeInfo

Source§

fn clone(&self) -> TypeInfo

Returns a duplicate 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 TypeInfo

Source§

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

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

impl<Salt> From<&TypeInfo> for ATypeId<Salt>

Source§

fn from(value: &TypeInfo) -> Self

Converts to this type from the input type.
Source§

impl From<&TypeInfo> for TypeIdExt

Source§

fn from(value: &TypeInfo) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for TypeInfo

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TypeInfo

Source§

impl Eq for TypeInfo

Source§

impl StructuralPartialEq for TypeInfo

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.