[−][src]Struct abi_stable::sabi_trait::robject::RObject
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
.RequiresT:'static
. -
as_unerased:Unwraps into a
&T
.RequiresT:'static
. -
as_unerased_mut:Unwraps into a
&mut T
.RequiresT:'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]
P: GetPointerKind<Target = ()>,
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]
ptr: OrigPtr,
vtable: StaticRef<V>
) -> RObject<'lt, P, I, V> where
OrigPtr: CanTransmuteElement<(), TransmutedPtr = P>,
OrigPtr::Target: Sized + 'lt,
P: Deref<Target = ()>,
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]
ptr: &'a T,
vtable: VTableTO_RO<T, RRef<'a, T>, Unerasability, V>
) -> Self where
T: 'borr,
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]
P: GetPointerKind,
pub fn into_unerased<T>(self) -> Result<P::TransmutedPtr, UneraseError<Self>> where
T: 'static,
P: Deref<Target = ()> + CanTransmuteElement<T>,
[src]
T: 'static,
P: Deref<Target = ()> + CanTransmuteElement<T>,
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 thisRObject<_>
was constructed with.
pub fn as_unerased<T>(&self) -> Result<&T, UneraseError<&Self>> where
T: 'static,
P: Deref<Target = ()> + CanTransmuteElement<T>,
[src]
T: 'static,
P: Deref<Target = ()> + CanTransmuteElement<T>,
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 thisRObject<_>
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]
T: 'static,
P: DerefMut<Target = ()> + CanTransmuteElement<T>,
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 thisRObject<_>
was constructed with.
pub unsafe fn unchecked_into_unerased<T>(self) -> P::TransmutedPtr where
P: Deref<Target = ()> + CanTransmuteElement<T>,
[src]
P: Deref<Target = ()> + CanTransmuteElement<T>,
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]
P: Deref<Target = ()>,
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]
P: DerefMut<Target = ()>,
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]
P: GetPointerKind,
I: InterfaceType,
pub fn reborrow<'re>(&'re self) -> RObject<'lt, &'re (), I, V> where
P: Deref<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
[src]
P: Deref<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
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]
P: DerefMut<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
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]
P: GetPointerKind,
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]
P: __DerefTrait<Target = ()>,
pub fn sabi_erased_mut(&mut self) -> &mut ErasedObject<()> where
P: __DerefMutTrait<Target = ()>,
[src]
P: __DerefMutTrait<Target = ()>,
pub fn sabi_with_value<F, R>(self, f: F) -> R where
P: OwnedPointer<Target = ()>,
F: FnOnce(MovePtr<()>) -> R,
[src]
P: OwnedPointer<Target = ()>,
F: FnOnce(MovePtr<()>) -> R,
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]
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
V: __GetStaticEquivalent_,
V: SharedStableAbi,
I: InterfaceBound,
type StaticEquivalent = _static_RObject<'static, __GetStaticEquivalent<P>, __GetStaticEquivalent<I>, __GetStaticEquivalent<V>>
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]
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
V: __GetStaticEquivalent_,
V: SharedStableAbi,
I: InterfaceBound,
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
const S_LAYOUT: &'static TypeLayout
[src]
const S_ABI_CONSTS: AbiConsts
[src]
impl<'lt, P, I, V> Send for RObject<'lt, P, I, V> where
P: GetPointerKind,
I: InterfaceType<Send = Implemented<Send>>,
[src]
P: GetPointerKind,
I: InterfaceType<Send = Implemented<Send>>,
impl<'lt, P, I, V> Sync for RObject<'lt, P, I, V> where
P: GetPointerKind,
I: InterfaceType<Sync = Implemented<Sync>>,
[src]
P: GetPointerKind,
I: InterfaceType<Sync = Implemented<Sync>>,
impl<'_, P, I, V> Drop for RObject<'_, P, I, V> where
P: GetPointerKind,
[src]
P: GetPointerKind,
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]
P: Deref + GetPointerKind,
I: InterfaceType,
Self: CloneImpl<<P as GetPointerKind>::Kind>,
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();
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'lt, P, I, V> Display for RObject<'lt, P, I, V> where
P: Deref<Target = ()> + GetPointerKind,
I: InterfaceType<Display = Implemented<Display>>,
[src]
P: Deref<Target = ()> + GetPointerKind,
I: InterfaceType<Display = Implemented<Display>>,
impl<'lt, P, I, V> Debug for RObject<'lt, P, I, V> where
P: Deref<Target = ()> + GetPointerKind,
I: InterfaceType<Debug = Implemented<Debug>>,
[src]
P: Deref<Target = ()> + GetPointerKind,
I: InterfaceType<Debug = Implemented<Debug>>,
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]
P: Deref<Target = ()> + GetPointerKind,
I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,
Auto Trait Implementations
impl<'lt, P, I, V> Unpin for RObject<'lt, P, I, V> where
I: Unpin,
P: Unpin,
I: Unpin,
P: Unpin,
impl<'lt, P, I, V> UnwindSafe for RObject<'lt, P, I, V> where
I: UnwindSafe,
P: UnwindSafe,
V: RefUnwindSafe,
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,
I: RefUnwindSafe,
P: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<This> StableAbi for This where
This: SharedStableAbi<Kind = ValueKind>,
[src]
This: SharedStableAbi<Kind = ValueKind>,
const LAYOUT: &'static TypeLayout
[src]
const ABI_CONSTS: AbiConsts
[src]
impl<This> TransmuteElement for This where
This: ?Sized,
[src]
This: ?Sized,
unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
Self::Target: Sized,
[src]
Self: CanTransmuteElement<T>,
Self::Target: Sized,
impl<'a, T> BorrowOwned<'a> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
type ROwned = T
type RBorrowed = &'a T
fn r_borrow(
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
fn r_to_owned(
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
[src]
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
fn deref_borrowed(&<T as BorrowOwned<'a>>::RBorrowed) -> &T
[src]
fn deref_owned(&<T as BorrowOwned<'a>>::ROwned) -> &T
[src]
fn from_cow_borrow(&'a T) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
fn from_cow_owned(<T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
[src]
fn into_cow_borrow(<T as BorrowOwned<'a>>::RBorrowed) -> &'a T
[src]
fn into_cow_owned(<T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> TypeIdentity for T where
T: ?Sized,
[src]
T: ?Sized,
type Type = T
The same type as Self. Read more
fn into_type_val(self) -> Self::Type where
Self::Type: Sized,
[src]
Self::Type: Sized,
fn into_type_ref(&self) -> &Self::Type
[src]
fn into_type_mut(&mut self) -> &mut Self::Type
[src]
fn into_type_box(self: Box<Self>) -> Box<Self::Type>
[src]
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
[src]
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
[src]
fn from_type_val(this: Self::Type) -> Self where
Self::Type: Sized,
[src]
Self::Type: Sized,
fn from_type_ref(this: &Self::Type) -> &Self
[src]
fn from_type_mut(this: &mut Self::Type) -> &mut Self
[src]
fn from_type_box(this: Box<Self::Type>) -> Box<Self>
[src]
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>
[src]
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>
[src]
impl<T> SelfOps for T where
T: ?Sized,
[src]
T: ?Sized,
const T: PhantomData<fn() -> Self>
[src]
const T_D: PhantomData<Self>
[src]
fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self
[src]
fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self
[src]
fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self
[src]
fn ty_(&self) -> PhantomData<fn() -> Self>
[src]
fn ty_d(&self) -> PhantomData<Self>
[src]
fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>
[src]
fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>
[src]
fn eq_id(&self, other: &Self) -> bool
[src]
fn piped<F, U>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
F: FnOnce(&'a Self) -> U,
[src]
F: FnOnce(&'a Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U where
F: FnOnce(&'a mut Self) -> U,
[src]
F: FnOnce(&'a mut Self) -> U,
fn mutated<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
fn observe<F>(self, f: F) -> Self where
F: FnOnce(&Self),
[src]
F: FnOnce(&Self),
fn into_<T>(self, PhantomData<fn() -> T>) -> T where
Self: Into<T>,
[src]
Self: Into<T>,
fn as_ref_<T>(&self) -> &T where
Self: AsRef<T>,
T: ?Sized,
[src]
Self: AsRef<T>,
T: ?Sized,
fn as_mut_<T>(&mut self) -> &mut T where
Self: AsMut<T>,
T: ?Sized,
[src]
Self: AsMut<T>,
T: ?Sized,
fn drop_(self)
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,