[][src]Struct abi_stable::VirtualWrapper

#[repr(C)]
pub struct VirtualWrapper<P> { /* fields omitted */ }

VirtualWrapper implements ffi-safe trait objects,for a selection of traits.

Passing opaque values around with VirtualWrapper<_>

One can pass non-StableAbi types around by using type erasure,using this type.

It generally looks like VirtualWrapper<Pointer<ZeroSized<Interface>>>,where:

  • Pointer is some pointer_trait::StableDeref pointer type.

  • ZeroSized is a zero-sized marker type.

  • Interface is an InterfaceType,which describes what traits are required when constructing the VirtualWrapper<_> and which ones it implements.

trait InterfaceType allows describing which traits are required when constructing a VirtualWrapper<_>,and which ones it implements.

Construction

To construct a VirtualWrapper<_> one can use these associated functions:

  • from_value: Can be constructed from the value directly. Requires a value that implements ImplType.

  • from_ptr: Can be constructed from a pointer of a value. Requires a value that implements ImplType.

  • from_any_value: Can be constructed from the value directly.Requires a 'static value.

  • from_any_ptr Can be constructed from a pointer of a value.Requires a 'static value.

Trait object

VirtualWrapper<Pointer<ZeroSized< Interface >>> can be used as a trait object for any combination of the traits listed bellow.

These are the traits:

  • Clone

  • Display

  • Debug

  • Default: Can be called as an inherent method.

  • Eq

  • PartialEq

  • Ord

  • PartialOrd

  • Hash

  • serde::Deserialize: first deserializes from a string,and then calls the objects' Deserialize impl.

  • serde::Serialize: first calls the objects' Deserialize impl,then serializes that as a string.

Deconstruction

VirtualWrapper<_> can then be unwrapped into a concrete type, within the same dynamic library/executable that constructed it, using these (fallible) conversion methods:

  • into_unerased: Unwraps into a pointer to T. Where VirtualWrapper<P<ZeroSized< Interface >>>'s Interface must equal <T as ImplType>::Interface

  • as_unerased: Unwraps into a &T. Where VirtualWrapper<P<ZeroSized< Interface >>>'s Interface must equal <T as ImplType>::Interface

  • as_unerased_mut: Unwraps into a &mut T. Where VirtualWrapper<P<ZeroSized< Interface >>>'s Interface must equal <T as ImplType>::Interface

  • into_mut_unerased:Unwraps into a pointer to T.Requires T:'static.

  • as_mut_unerased:Unwraps into a &T.Requires T:'static.

  • as_mut_unerased_mut:Unwraps into a &mut T.Requires T:'static.

Methods

impl VirtualWrapper<()>[src]

pub fn from_value<T>(object: T) -> VirtualWrapper<RBox<ZeroSized<T::Interface>>> where
    T: ImplType,
    T: GetVtable<T, RBox<ZeroSized<<T as ImplType>::Interface>>, RBox<T>>, 
[src]

Constructors the VirtualWrapper<_> from an ImplType implementor.

Use this whenever possible instead of from_any_value, because it produces better error messages when unerasing the VirtualWrapper<_>

pub fn from_ptr<P, T>(object: P) -> VirtualWrapper<P::TransmutedPtr> where
    P: StableDeref<Target = T>,
    T: ImplType,
    T: GetVtable<T, P::TransmutedPtr, P>,
    P: ErasedStableDeref<<T as ImplType>::Interface>, 
[src]

Constructors the VirtualWrapper<_> from a pointer to an ImplType implementor.

Use this whenever possible instead of from_any_ptr, because it produces better error messages when unerasing the VirtualWrapper<_>

pub fn from_any_value<T, I>(
    object: T,
    interface: I
) -> VirtualWrapper<RBox<ZeroSized<I>>> where
    T: 'static,
    I: InterfaceType,
    InterfaceFor<T, I>: GetVtable<T, RBox<ZeroSized<I>>, RBox<T>>, 
[src]

Constructors the VirtualWrapper<_> from a type which doesn't borrow anything.

pub fn from_any_ptr<P, T, I>(
    object: P,
    _interface: I
) -> VirtualWrapper<P::TransmutedPtr> where
    I: InterfaceType,
    P: StableDeref<Target = T>,
    T: 'static,
    InterfaceFor<T, I>: GetVtable<T, P::TransmutedPtr, P>,
    P: ErasedStableDeref<I>, 
[src]

Constructors the VirtualWrapper<_> from a pointer to a type which doesn't borrow anything.

impl<P> VirtualWrapper<P>[src]

pub fn is_same_type<Other>(&self, other: &VirtualWrapper<Other>) -> bool[src]

Allows checking whether 2 VirtualWrapper<_>s have a value of the same type.

Note that types from different dynamic libraries/executables are never considered equal.

pub fn object_address(&self) -> usize where
    P: Deref
[src]

Returns the address of the wrapped object.

This will not change between calls for the same VirtualWrapper<_>.

impl<P> VirtualWrapper<P>[src]

pub fn into_unerased<T>(self) -> Result<P::TransmutedPtr, UneraseError> where
    P: TransmuteElement<T>,
    P::Target: Sized,
    T: ImplType + GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a pointer of the concrete type that it was constructed with.

T is required to implement ImplType.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

pub fn as_unerased<T>(&self) -> Result<&T, UneraseError> where
    P: Deref + TransmuteElement<T>,
    T: ImplType + GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a reference of the concrete type that it was constructed with.

T is required to implement ImplType.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

pub fn as_unerased_mut<T>(&mut self) -> Result<&mut T, UneraseError> where
    P: DerefMut + TransmuteElement<T>,
    T: ImplType + GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a mutable reference of the concrete type that it was constructed with.

T is required to implement ImplType.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

pub fn into_any_unerased<T>(self) -> Result<P::TransmutedPtr, UneraseError> where
    P: TransmuteElement<T>,
    P::Target: Sized,
    Self: VirtualWrapperTrait,
    InterfaceFor<T, GetVWInterface<Self>>: GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a pointer of the concrete type that it was constructed with.

T is required to not borrows anything.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

pub fn as_any_unerased<T>(&self) -> Result<&T, UneraseError> where
    P: Deref + TransmuteElement<T>,
    Self: VirtualWrapperTrait,
    InterfaceFor<T, GetVWInterface<Self>>: GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a reference of the concrete type that it was constructed with.

T is required to not borrows anything.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

pub fn as_any_unerased_mut<T>(&mut self) -> Result<&mut T, UneraseError> where
    P: DerefMut + TransmuteElement<T>,
    Self: VirtualWrapperTrait,
    InterfaceFor<T, GetVWInterface<Self>>: GetVtable<T, P, P::TransmutedPtr>, 
[src]

Unwraps the VirtualWrapper<_> into a mutable reference of the concrete type that it was constructed with.

T is required to not borrows anything.

Errors

This will return an error in any of these conditions:

  • It is called in a dynamic library/binary outside the one from which this VirtualWrapper<_> was constructed.

  • T is not the concrete type this VirtualWrapper<_> was constructed with.

impl<P> VirtualWrapper<P>[src]

pub fn default<I>(&self) -> Self where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Default = True>, 
[src]

Constructs a VirtualWrapper<P> with the default value for P.

pub fn serialized<'a, I>(&'a self) -> Result<RCow<'a, RStr<'a>>, RBoxError> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Serialize = True>, 
[src]

It serializes a VirtualWrapper<_> into a string by using <ConcreteType as SerializeImplType>::serialize_impl.

pub fn deserialize_from_str<'a, I>(s: &'a str) -> Result<Self, RBoxError> where
    P: Deref<Target = ZeroSized<I>>,
    I: DeserializeInterfaceType<Deserialize = True, Deserialized = Self>, 
[src]

Deserializes a string into a VirtualWrapper<_>,by using <I as DeserializeInterfaceType>::deserialize_impl.

Trait Implementations

impl<P> SharedStableAbi for VirtualWrapper<P> where
    P: __StableAbi
[src]

type IsNonZeroType = False

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

type StaticEquivalent = VirtualWrapper<__StaticEquivalent<P>>

A version of the type which does not borrow anything, used to create a UTypeId for doing layout checking. Read more

const S_ABI_INFO: &'static AbiInfoWrapper[src]

The layout of the type,derived from Self::LAYOUT and associated types.

impl<P, I> VirtualWrapperTrait for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType
[src]

type Interface = I

impl<P, I> Eq for VirtualWrapper<P> where
    Self: PartialEq,
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Eq = True>, 
[src]

impl<P, I> PartialOrd<VirtualWrapper<P>> for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<PartialOrd = True>,
    Self: PartialEq
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

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

impl<P, I> PartialEq<VirtualWrapper<P>> for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<PartialEq = True>, 
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl<P, I> Clone for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Clone = True>, 
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<P, I> Ord for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Ord = True>,
    Self: PartialOrd + Eq
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<P> Drop for VirtualWrapper<P>[src]

impl<P, I> Display for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Display = True>, 
[src]

impl<P, I> Debug for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Debug = True>, 
[src]

impl<P, I> Hash for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Hash = True>, 
[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl<'a, P, I> Deserialize<'a> for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: DeserializeInterfaceType<Deserialize = True, Deserialized = Self>, 
[src]

First it Deserializes a string,then it deserializes into a VirtualWrapper<_>,by using <I as DeserializeInterfaceType>::deserialize_impl.

impl<P, I> Serialize for VirtualWrapper<P> where
    P: Deref<Target = ZeroSized<I>>,
    I: InterfaceType<Serialize = True>, 
[src]

First it serializes a VirtualWrapper<_> into a string by using ::serialize_impl, then it serializes the string. ,then it .

Auto Trait Implementations

impl<P> !Send for VirtualWrapper<P>

impl<P> !Sync for VirtualWrapper<P>

Blanket Implementations

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

impl<T> MakeGetAbiInfo for T where
    T: StableAbi
[src]

impl<T> MakeGetAbiInfo for T where
    T: SharedStableAbi
[src]

impl<T> MakeGetAbiInfo for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more

fn into_type_val(self) -> Self::Type where
    Self::Type: Sized
[src]

Converts a value back to the original type.

fn into_type_ref(&self) -> &Self::Type[src]

Converts a reference back to the original type.

fn into_type_mut(&mut self) -> &mut Self::Type[src]

Converts a mutable reference back to the original type.

fn into_type_box(self: Box<Self>) -> Box<Self::Type>[src]

Converts a box back to the original type.

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>[src]

Converts an Arc back to the original type.

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>[src]

Converts an Rc back to the original type.

fn from_type_val(this: Self::Type) -> Self where
    Self::Type: Sized
[src]

Converts a value back to the original type.

fn from_type_ref(this: &Self::Type) -> &Self[src]

Converts a reference back to the original type.

fn from_type_mut(this: &mut Self::Type) -> &mut Self[src]

Converts a mutable reference back to the original type.

fn from_type_box(this: Box<Self::Type>) -> Box<Self>[src]

Converts a box back to the original type.

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>[src]

Converts an Arc back to the original type.

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>[src]

Converts an Rc back to the original type.

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

const T: PhantomData<fn() -> Self>[src]

Represents Self by using a VariantPhantom, using the syntax Type::T to pass it in methods with _:VariantPhantom<T> parameters. Read more

const T_D: PhantomData<Self>[src]

Represents Self by using a VariantDropPhantom,for specialized cases. Read more

fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self[src]

Asserts that other is the same type as self.

fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self[src]

Asserts that other is the same type as self.

fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self[src]

Asserts that other is the same type as self.

fn ty_(&self) -> PhantomData<fn() -> Self>[src]

Equivalent to SelfOps::T,as a method. Read more

fn ty_d(&self) -> PhantomData<Self>[src]

Equivalent to [Self::ty_],for specialized cases. Read more

fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>[src]

Equivalent to [Self::ty_] with an invariant type.

fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>[src]

Equivalent to [Self::ty_] with an invariant lifetime.

fn eq_id(&self, other: &Self) -> bool[src]

Identity comparison to another value of the same type. Read more

fn piped<F, U>(self, f: F) -> U where
    F: FnOnce(Self) -> U, 
[src]

Emulates the pipeline operator,allowing method syntax in more places. Read more

fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
    F: FnOnce(&'a Self) -> U, 
[src]

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U where
    F: FnOnce(&'a mut Self) -> U, 
[src]

The same as piped except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self. Read more

fn mutated<F>(self, f: F) -> Self where
    F: FnOnce(&mut Self), 
[src]

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more

fn observe<F>(self, f: F) -> Self where
    F: FnOnce(&Self), 
[src]

Observes the value of self passing it along unmodified. Useful in a long method chain. Read more

fn into_<T>(self, PhantomData<fn() -> T>) -> T where
    Self: Into<T>, 
[src]

Performs a conversion using Into. Read more

fn as_ref_<T>(&self) -> &T where
    Self: AsRef<T>,
    T: ?Sized
[src]

Performs a reference to reference conversion using AsRef, using the turbofish .as_ref_::<_>() syntax. Read more

fn as_mut_<T>(&mut self) -> &mut T where
    Self: AsMut<T>,
    T: ?Sized
[src]

Performs a mutable reference to mutable reference conversion using AsMut, using the turbofish .as_mut_::<_>() syntax. Read more

fn drop_(self)[src]

Drops self using method notation. Alternative to std::mem::drop. Read more

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

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

The error type returned when the conversion fails.

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Erased for T