[][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.

A workaround for it not being possible to get a function pointer within a const fn, since it's possible to pass structs that happen to have function pointer fields.

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);

Implementations

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> StableAbi for Constructor<T> where
    T: __StableAbi
[src]

type IsNonZeroType = True

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

Auto Trait Implementations

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

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

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

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

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

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

The owned type, stored in RCow::Owned

type RBorrowed = &'a T

The borrowed type, stored in RCow::Borrowed

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

impl<T> GetWithMetadata for T[src]

type ForSelf = WithMetadata_<T, T>

This is always WithMetadata_<Self, Self>

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

impl<T> SelfOps for T where
    T: ?Sized
[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

impl<This> ValidTag_Bounds for This where
    This: Debug + Clone + PartialEq<This>, 
[src]