[][src]Struct abi_stable::sabi_trait::RObject

#[repr(C)]pub struct RObject<'lt, P, I, V> where
    P: GetPointerKind
{ /* fields omitted */ }

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

The main use of RObject<_> is as the default backend for #[sabi_trait] generated trait objects.

Construction

RObject<_> is how #[sabi_trait]-based ffi-safe trait objects are implemented, and there's no way to construct it separate from those.

Trait object

RObject<'borrow,Pointer<()>,Interface,VTable> can be used as a trait object for any combination of the traits listed below.

These are the traits:

  • Send

  • Sync

  • Debug

  • Display

  • Error

  • Clone

Deconstruction

RObject<_> can 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.Requires T: 'static.

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

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

RObject can only be converted back if the trait object was constructed to allow it.

Implementations

impl<'lt, P, I, V> RObject<'lt, P, I, V> where
    P: GetPointerKind<Target = ()>, 
[src]

pub unsafe fn with_vtable<OrigPtr>(
    ptr: OrigPtr,
    vtable: PrefixRef<V>
) -> RObject<'lt, P, I, V> where
    OrigPtr: CanTransmuteElement<(), TransmutedPtr = P>,
    OrigPtr::Target: Sized + 'lt,
    P: Deref<Target = ()>, 
[src]

Constructs an RObject from a pointer and an extra vtable.

This is mostly intended to be called by #[sabi_trait] generated trait objects.

Safety

These are the requirements for the caller:

  • P must be a pointer to the type that the vtable functions take as the first parameter.

  • The vtable must not come from a reborrowed RObject (created using RObject::reborrow or RObject::reborrow_mut).

  • The vtable must be the SomeVTableName of a struct declared with #[derive(StableAbi)] #[sabi(kind(Prefix(prefix_ref="SomeVTableName")))].

  • The vtable must have RObjectVtable_Ref as its first declared field

impl<'borr, 'a, I, V> RObject<'borr, RRef<'a, ()>, I, V>[src]

pub const unsafe fn with_vtable_const<T, Unerasability>(
    ptr: &'a T,
    vtable: VTableTO_RO<T, RRef<'a, T>, Unerasability, V>
) -> Self where
    T: 'borr, 
[src]

This function allows constructing an RObject in a constant/static.

This is mostly intended for #[sabi_trait] generated trait objects

Safety

This has the same safety requirements as RObject::with_vtable

Example

Because this is intended for #[sabi_trait] generated trait objects, this demonstrates how to construct one in a constant.

use abi_stable::sabi_trait::{
    doc_examples::{ConstExample_CTO,ConstExample_MV},
    prelude::TU_Opaque,
};

const EXAMPLE0:ConstExample_CTO<'static,'static>=
    ConstExample_CTO::from_const(
        &0usize,
        TU_Opaque,
        ConstExample_MV::VTABLE,
    );

impl<'lt, P, I, V> RObject<'lt, P, I, V> where
    P: GetPointerKind
[src]

pub fn into_unerased<T>(self) -> Result<P::TransmutedPtr, UneraseError<Self>> where
    T: 'static,
    P: Deref<Target = ()> + CanTransmuteElement<T>, 
[src]

Attempts to unerase this trait object into the pointer it was constructed with.

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 RObject was constructed.

  • The trait object wrapping this RObject was constructed with a TU_Unerasable argument.

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

pub fn as_unerased<T>(&self) -> Result<&T, UneraseError<&Self>> where
    T: 'static,
    P: Deref<Target = ()> + CanTransmuteElement<T>, 
[src]

Attempts to unerase this trait object into a reference of the value was constructed with.

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 RObject was constructed.

  • The trait object wrapping this RObject was constructed with a TU_Unerasable argument.

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

pub fn as_unerased_mut<T>(&mut self) -> Result<&mut T, UneraseError<&mut Self>> where
    T: 'static,
    P: DerefMut<Target = ()> + CanTransmuteElement<T>, 
[src]

Attempts to unerase this trait object into a mutable reference of the value was constructed with.

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 RObject was constructed.

  • The trait object wrapping this RObject was constructed with a TU_Unerasable argument.

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

pub unsafe fn unchecked_into_unerased<T>(self) -> P::TransmutedPtr where
    P: Deref<Target = ()> + CanTransmuteElement<T>, 
[src]

Unwraps the RObject<_> into a pointer to T, without checking whether T is the type that the RObject was constructed with.

Safety

You must check that T is the type that RObject was constructed with through other means.

pub unsafe fn unchecked_as_unerased<T>(&self) -> &T where
    P: Deref<Target = ()>, 
[src]

Unwraps the RObject<_> into a reference to T, without checking whether T is the type that the RObject was constructed with.

Safety

You must check that T is the type that RObject was constructed with through other means.

pub unsafe fn unchecked_as_unerased_mut<T>(&mut self) -> &mut T where
    P: DerefMut<Target = ()>, 
[src]

Unwraps the RObject<_> into a mutable reference to T, without checking whether T is the type that the RObject was constructed with.

Safety

You must check that T is the type that RObject was constructed with through other means.

impl<'lt, P, I, V> RObject<'lt, P, I, V> where
    P: GetPointerKind,
    I: InterfaceType
[src]

pub fn reborrow<'re>(&'re self) -> RObject<'lt, &'re (), I, V> where
    P: Deref<Target = ()>,
    PrivStruct: ReborrowBounds<I::Send, I::Sync>, 
[src]

Creates a shared reborrow of this RObject.

This is only callable if RObject is either Send + Sync or !Send + !Sync.

pub fn reborrow_mut<'re>(&'re mut self) -> RObject<'lt, &'re mut (), I, V> where
    P: DerefMut<Target = ()>,
    PrivStruct: ReborrowBounds<I::Send, I::Sync>, 
[src]

Creates a mutable reborrow of this RObject.

The reborrowed RObject cannot use these methods:

  • RObject::clone

This is only callable if RObject is either Send + Sync or !Send + !Sync.

impl<'lt, P, I, V> RObject<'lt, P, I, V> where
    P: GetPointerKind
[src]

pub fn sabi_et_vtable(&self) -> PrefixRef<V>[src]

Gets the vtable.

pub fn sabi_robject_vtable(&self) -> RObjectVtable_Ref<(), P, I>[src]

The vtable common to all #[sabi_trait] generated trait objects.

pub fn sabi_erased_ref(&self) -> &ErasedObject<()> where
    P: __DerefTrait<Target = ()>, 
[src]

Gets an RRef pointing to the erased object.

pub fn sabi_erased_mut(&mut self) -> &mut ErasedObject<()> where
    P: __DerefMutTrait<Target = ()>, 
[src]

Gets an RMut pointing to the erased object.

pub fn sabi_as_rref(&self) -> RRef<'_, ()> where
    P: __DerefTrait<Target = ()>, 
[src]

Gets an RRef pointing to the erased object.

pub fn sabi_as_rmut(&mut self) -> RMut<'_, ()> where
    P: __DerefMutTrait<Target = ()>, 
[src]

Gets an RMut pointing to the erased object.

pub fn sabi_with_value<F, R>(self, f: F) -> R where
    P: OwnedPointer<Target = ()>,
    F: FnOnce(MovePtr<'_, ()>) -> R, 
[src]

Calls the f callback with an MovePtr pointing to the erased object.

Trait Implementations

impl<'lt, P, I, V> Clone for RObject<'lt, P, I, V> where
    P: Deref + GetPointerKind,
    I: InterfaceType,
    Self: CloneImpl<<P as GetPointerKind>::Kind>, 
[src]

Clone is implemented for references and smart pointers, using GetPointerKind to decide whether P is a smart pointer or a reference.

RObject does not implement Clone if P==&mut () :

use abi_stable::{
    sabi_trait::{
        doc_examples::ConstExample_TO,
        TU_Opaque,
    },
    std_types::*,
};

let mut object=ConstExample_TO::from_value(10usize,TU_Opaque);
let borrow=object.sabi_reborrow_mut();
let _=borrow.clone();

Here is the same example with sabi_reborrow

use abi_stable::{
    sabi_trait::{
        doc_examples::ConstExample_TO,
        TU_Opaque,
    },
    std_types::*,
};

let mut object=ConstExample_TO::from_value(10usize,TU_Opaque);
let borrow=object.sabi_reborrow();
let _=borrow.clone();

impl<'lt, P, I, V> Debug for RObject<'lt, P, I, V> where
    P: Deref<Target = ()> + GetPointerKind,
    I: InterfaceType<Debug = Implemented<Debug>>, 
[src]

impl<'lt, P, I, V> Display for RObject<'lt, P, I, V> where
    P: Deref<Target = ()> + GetPointerKind,
    I: InterfaceType<Display = Implemented<Display>>, 
[src]

impl<P, I, V> Drop for RObject<'_, P, I, V> where
    P: GetPointerKind
[src]

impl<'lt, P, I, V> Error for RObject<'lt, P, I, V> where
    P: Deref<Target = ()> + GetPointerKind,
    I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>, 
[src]

impl<'lt, P, I, V> GetStaticEquivalent_ for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    P: __StableAbi,
    I: __StableAbi,
    V: __GetStaticEquivalent_,
    V: PrefixStableAbi,
    I: InterfaceBound
[src]

impl<'lt, P, I, V> Send for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    I: InterfaceType<Send = Implemented<Send>>, 
[src]

impl<'lt, P, I, V> StableAbi for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    P: __StableAbi,
    I: __StableAbi,
    V: __GetStaticEquivalent_,
    V: PrefixStableAbi,
    I: InterfaceBound
[src]

type IsNonZeroType = False

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

impl<'lt, P, I, V> Sync for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    I: InterfaceType<Sync = Implemented<Sync>>, 
[src]

Auto Trait Implementations

impl<'lt, P, I, V> RefUnwindSafe for RObject<'lt, P, I, V> where
    I: RefUnwindSafe,
    P: RefUnwindSafe,
    V: RefUnwindSafe
[src]

impl<'lt, P, I, V> Unpin for RObject<'lt, P, I, V> where
    I: Unpin,
    P: Unpin
[src]

impl<'lt, P, I, V> UnwindSafe for RObject<'lt, P, I, V> where
    I: UnwindSafe,
    P: UnwindSafe,
    V: RefUnwindSafe
[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