[][src]Struct abi_stable::sabi_trait::robject::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

To construct an RObject<_> directly (not as part of a trait object) you can call one of these methods:

  • from_ptr Can be constructed from a pointer of a value.Cannot unerase the RObject afterwards.

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

  • from_value: Can be constructed from the value directly.Cannot unerase the RObject afterwards.

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

Trait object

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

These are the traits:

  • Send

  • Sync

  • Debug

  • Clone

Deconstruction

RObject<_> 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.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 it was created using a RObject::*_unerased function.

Methods

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

pub unsafe fn with_vtable<OrigPtr>(
    ptr: OrigPtr,
    vtable: StaticRef<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_struct="<SomeVTableName>")))].

  • The vtable must have StaticRef<RObjectVtable<..>> 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 RObject was constructed using the from_(value|ptr) method

  • 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 RObject was constructed using the from_(value|ptr) method

  • 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 RObject was constructed using the frfrom_(value|ptr)_* method

  • 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.

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

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

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

pub fn sabi_robject_vtable<'a>(&self) -> &'a RObjectVtable<(), 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]

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

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

Trait Implementations

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

impl<'lt, P, I, V> SharedStableAbi for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    P: __StableAbi,
    I: __StableAbi,
    V: __GetStaticEquivalent_,
    V: SharedStableAbi,
    I: InterfaceBound
[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

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> Sync for RObject<'lt, P, I, V> where
    P: GetPointerKind,
    I: InterfaceType<Sync = Implemented<Sync>>, 
[src]

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

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 () :

This example deliberately fails to compile
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> Display for RObject<'lt, P, I, V> where
    P: Deref<Target = ()> + GetPointerKind,
    I: InterfaceType<Display = Implemented<Display>>, 
[src]

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> Error for RObject<'lt, P, I, V> where
    P: Deref<Target = ()> + GetPointerKind,
    I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>, 
[src]

Auto Trait Implementations

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

impl<'lt, P, I, V> UnwindSafe for RObject<'lt, P, I, V> where
    I: UnwindSafe,
    P: UnwindSafe,
    V: RefUnwindSafe

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

Blanket Implementations

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

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

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

type ROwned = T

type RBorrowed = &'a T

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

impl<T> From<T> for T[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<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> Borrow<T> for T where
    T: ?Sized
[src]

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

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

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

type Type = T

The same type as Self. Read more

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

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.