[][src]Struct abi_stable::sabi_types::Constructor

#[repr(transparent)]
pub struct Constructor<T>(pub extern "C" fn() -> T);

Newtype wrapper to pass function pointers to const fn.

Every impl of this type delegates the impl to the return value of the wrapped function (which it calls every time),don't use those impls if the function is likely expensive.

Example

use abi_stable::{
    sabi_types::Constructor,
    std_types::{ROption,RNone,RSome},
};


extern "C" fn returns_100()->ROption<u32>{
    RSome(100)
}

extern "C" fn returns_100b()->ROption<u32>{
    RSome(100)
}

extern "C" fn returns_200()->ROption<u32>{
    RSome(200)
}

extern "C" fn returns_none()->ROption<u32>{
    RNone
}


const A: Constructor<ROption<u32>>= Constructor(returns_100);
const B: Constructor<ROption<u32>>= Constructor(returns_100b);
const C: Constructor<ROption<u32>>= Constructor(returns_200);
const D: Constructor<ROption<u32>>= Constructor(returns_none);

assert_eq!(A,A);
assert_eq!(B,B);
assert_eq!(C,C);
assert_eq!(D,D);

assert_eq!(A,B);

assert_ne!(A,C);
assert_ne!(A,D);
assert_ne!(B,C);
assert_ne!(C,D);

Methods

impl<T> Constructor<T>[src]

pub fn get(self) -> T[src]

Constructs a T by calling the wrapped function.

Trait Implementations

impl<T> Clone for Constructor<T>[src]

impl<T> Copy for Constructor<T>[src]

impl<T> Debug for Constructor<T> where
    T: Debug
[src]

impl<T> Display for Constructor<T> where
    T: Display
[src]

impl<T> Eq for Constructor<T> where
    T: Eq
[src]

impl<T> GetStaticEquivalent_ for Constructor<T> where
    T: __StableAbi
[src]

type StaticEquivalent = _static_Constructor<__GetStaticEquivalent<T>>

impl<T> Ord for Constructor<T> where
    T: Ord
[src]

impl<T> PartialEq<Constructor<T>> for Constructor<T> where
    T: PartialEq
[src]

impl<T> PartialOrd<Constructor<T>> for Constructor<T> where
    T: PartialOrd
[src]

impl<T> SharedStableAbi for Constructor<T> where
    T: __StableAbi
[src]

type IsNonZeroType = True

Whether this type has a single invalid bit-pattern. Read more

type Kind = __ValueKind

The kind of abi stability of this type,there are 2: Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for Constructor<T>

impl<T> Send for Constructor<T>

impl<T> Sync for Constructor<T>

impl<T> Unpin for Constructor<T>

impl<T> UnwindSafe for Constructor<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T> BorrowOwned<'a> for T where
    T: 'a + Clone
[src]

type ROwned = T

type RBorrowed = &'a T

impl<T> From<T> for T[src]

impl<This> GetConstGenericVTable for This where
    This: StableAbi + Eq + PartialEq<This> + Debug + Send + Sync
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SelfOps for T where
    T: ?Sized
[src]

impl<This> StableAbi for This where
    This: SharedStableAbi<Kind = ValueKind>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<This> TransmuteElement for This where
    This: ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The error type returned when the conversion fails.

impl<T> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more