[−][src]Struct abi_stable::sabi_trait::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
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 toT
.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 the trait object was constructed to allow it.
Implementations
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: PrefixRef<V>
) -> RObject<'lt, P, I, V> where
OrigPtr: CanTransmuteElement<(), TransmutedPtr = P>,
OrigPtr::Target: Sized + 'lt,
P: Deref<Target = ()>,
[src]
ptr: OrigPtr,
vtable: PrefixRef<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 usingRObject::reborrow
orRObject::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]
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 trait object wrapping this
RObject
was constructed with aTU_Unerasable
argument. -
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 trait object wrapping this
RObject
was constructed with aTU_Unerasable
argument. -
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 trait object wrapping this
RObject
was constructed with aTU_Unerasable
argument. -
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.
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]
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
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]
P: GetPointerKind,
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]
P: __DerefTrait<Target = ()>,
Gets an RRef
pointing to the erased object.
pub fn sabi_erased_mut(&mut self) -> &mut ErasedObject<()> where
P: __DerefMutTrait<Target = ()>,
[src]
P: __DerefMutTrait<Target = ()>,
Gets an RMut
pointing to the erased object.
pub fn sabi_as_rref(&self) -> RRef<'_, ()> where
P: __DerefTrait<Target = ()>,
[src]
P: __DerefTrait<Target = ()>,
Gets an RRef
pointing to the erased object.
pub fn sabi_as_rmut(&mut self) -> RMut<'_, ()> where
P: __DerefMutTrait<Target = ()>,
[src]
P: __DerefMutTrait<Target = ()>,
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]
P: OwnedPointer<Target = ()>,
F: FnOnce(MovePtr<'_, ()>) -> R,
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]
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();
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
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> 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<P, I, V> Drop for RObject<'_, P, I, V> where
P: GetPointerKind,
[src]
P: GetPointerKind,
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>>,
pub fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
pub fn description(&self) -> &str
1.0.0[src]
pub fn cause(&self) -> Option<&dyn Error>
1.0.0[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]
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
V: __GetStaticEquivalent_,
V: PrefixStableAbi,
I: InterfaceBound,
type StaticEquivalent = _static_RObject<'static, __GetStaticEquivalent<P>, __GetStaticEquivalent<I>, __GetStaticEquivalent<V>>
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> StableAbi for RObject<'lt, P, I, V> where
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
V: __GetStaticEquivalent_,
V: PrefixStableAbi,
I: InterfaceBound,
[src]
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
V: __GetStaticEquivalent_,
V: PrefixStableAbi,
I: InterfaceBound,
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
pub const LAYOUT: &'static TypeLayout
[src]
pub const ABI_CONSTS: AbiConsts
[src]
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>>,
Auto Trait Implementations
impl<'lt, P, I, V> RefUnwindSafe for RObject<'lt, P, I, V> where
I: RefUnwindSafe,
P: RefUnwindSafe,
V: RefUnwindSafe,
[src]
I: RefUnwindSafe,
P: RefUnwindSafe,
V: RefUnwindSafe,
impl<'lt, P, I, V> Unpin for RObject<'lt, P, I, V> where
I: Unpin,
P: Unpin,
[src]
I: Unpin,
P: Unpin,
impl<'lt, P, I, V> UnwindSafe for RObject<'lt, P, I, V> where
I: UnwindSafe,
P: UnwindSafe,
V: RefUnwindSafe,
[src]
I: UnwindSafe,
P: UnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T> BorrowOwned<'a> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
type ROwned = T
The owned type, stored in RCow::Owned
type RBorrowed = &'a T
The borrowed type, stored in RCow::Borrowed
pub 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
pub 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
pub fn deref_borrowed(&<T as BorrowOwned<'a>>::RBorrowed) -> &T
[src]
pub fn deref_owned(&<T as BorrowOwned<'a>>::ROwned) -> &T
[src]
pub fn from_cow_borrow(&'a T) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
pub fn from_cow_owned(<T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
[src]
pub fn into_cow_borrow(<T as BorrowOwned<'a>>::RBorrowed) -> &'a T
[src]
pub fn into_cow_owned(<T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
[src]
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]
U: From<T>,
impl<T> SelfOps for T where
T: ?Sized,
[src]
T: ?Sized,
pub const T: PhantomData<fn() -> Self>
[src]
pub const T_D: PhantomData<Self>
[src]
pub fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self
[src]
pub fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self
[src]
pub fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self
[src]
pub fn ty_(&self) -> PhantomData<fn() -> Self>
[src]
pub fn ty_d(&self) -> PhantomData<Self>
[src]
pub fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>
[src]
pub fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>
[src]
pub fn eq_id(&self, other: &Self) -> bool
[src]
pub fn piped<F, U>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
pub fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
F: FnOnce(&'a Self) -> U,
[src]
F: FnOnce(&'a Self) -> U,
pub 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,
pub fn mutated<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
pub fn observe<F>(self, f: F) -> Self where
F: FnOnce(&Self),
[src]
F: FnOnce(&Self),
pub fn into_<T>(self, PhantomData<fn() -> T>) -> T where
Self: Into<T>,
[src]
Self: Into<T>,
pub fn as_ref_<T>(&self) -> &T where
Self: AsRef<T>,
T: ?Sized,
[src]
Self: AsRef<T>,
T: ?Sized,
pub fn as_mut_<T>(&mut self) -> &mut T where
Self: AsMut<T>,
T: ?Sized,
[src]
Self: AsMut<T>,
T: ?Sized,
pub fn drop_(self)
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<This> TransmuteElement for This where
This: ?Sized,
[src]
This: ?Sized,
pub unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
Self::Target: Sized,
[src]
Self: CanTransmuteElement<T>,
Self::Target: 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.
pub 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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::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 error type returned when the conversion fails.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> TypeIdentity for T where
T: ?Sized,
[src]
T: ?Sized,
type Type = T
The same type as Self. Read more
pub fn into_type_val(self) -> Self::Type where
Self::Type: Sized,
[src]
Self::Type: Sized,
pub fn into_type_ref(&self) -> &Self::Type
[src]
pub fn into_type_mut(&mut self) -> &mut Self::Type
[src]
pub fn into_type_box(self: Box<Self, Global>) -> Box<Self::Type, Global>
[src]
pub fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
[src]
pub fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
[src]
pub fn from_type_val(this: Self::Type) -> Self where
Self::Type: Sized,
[src]
Self::Type: Sized,