Struct abi_stable::DynTrait
source · #[repr(C)]pub struct DynTrait<'borr, P, I, EV = ()>where
P: GetPointerKind,{ /* private fields */ }
Expand description
DynTrait implements ffi-safe trait objects, for a selection of traits.
Passing opaque values around with DynTrait<_>
One can pass non-StableAbi types around by using type erasure, using this type.
It generally looks like DynTrait<'borrow, Pointer<()>, Interface>
, where:
-
'borrow
is the borrow that the type that was erased had. -
Pointer
is a pointer type that implementsAsPtr
. -
Interface
is anInterfaceType
, which describes what traits are required when constructing theDynTrait<_>
and which ones it implements.
The InterfaceType
trait allows describing which traits are required
when constructing a DynTrait<_>
, and which ones it implements.
Construction
To construct a DynTrait<_>
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. -
from_borrowing_value
: Can be constructed from the value directly.Cannot downcast the DynTrait afterwards. -
from_borrowing_ptr
Can be constructed from a pointer of a value.Cannot downcast the DynTrait afterwards.
DynTrait uses the impls of the value in methods, which means that the pointer itself does not have to implement those traits,
Trait object
DynTrait<'borrow, Pointer<()>, Interface>
can be used as a trait object for any combination of
the traits listed below.
These are the traits:
-
Send
-
Sync
-
Iterator
-
DoubleEndedIterator
-
std::fmt::Write
-
std::io::Write
-
std::io::Seek
-
std::io::Read
-
std::io::BufRead
-
Clone
-
Display
-
Debug
-
std::error::Error
-
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
DynTrait<_>
can then be unwrapped into a concrete type,
within the same dynamic library/executable that constructed it,
using these (fallible) conversion methods:
-
downcast_into_impltype
: Unwraps into a pointer toT
. WhereDynTrait<P<()>, Interface>
’s Interface must equal<T as ImplType>::Interface
-
downcast_as_impltype
: Unwraps into a&T
. WhereDynTrait<P<()>, Interface>
’s Interface must equal<T as ImplType>::Interface
-
downcast_as_mut_impltype
: Unwraps into a&mut T
. WhereDynTrait<P<()>, Interface>
’s Interface must equal<T as ImplType>::Interface
-
downcast_into
: Unwraps into a pointer toT
.RequiresT:'static
. -
downcast_as
: Unwraps into a&T
.RequiresT:'static
. -
downcast_as_mut
: Unwraps into a&mut T
.RequiresT:'static
.
DynTrait
cannot be converted back if it was created
using DynTrait::from_borrowing_*
.
Passing DynTrait between dynamic libraries
Passing DynTrait between dynamic libraries (as in between the dynamic libraries directly loaded by the same binary/dynamic library) may cause the program to panic at runtime with an error message stating that the trait is not implemented for the specific interface.
This can only happen if you are passing DynTrait between dynamic libraries, or if DynTrait was instantiated in the parent passed to a child, a DynTrait instantiated in a child dynamic library passed to the parent should not cause a panic, it would be a bug.
binary
_________|___________
lib0 lib1 lib2
| | |
lib00 lib10 lib20
In this diagram passing a DynTrait constructed in lib00 to anything other than the binary or lib0 will cause the panic to happen if:
-
The
InterfaceType
requires extra traits in the version of the Interface that lib1 and lib2 know about (that the binary does not require). -
lib1 or lib2 attempt to call methods that require the traits that were added to the
InterfaceType
, in versions of that interface that only they know about.
serializing/deserializing DynTraits
To be able to serialize and deserialize a DynTrait,
the interface it uses must implement SerializeProxyType
and DeserializeDyn
,
and the implementation type must implement SerializeImplType
.
For a more realistic example you can look at the “examples/0_modules_and_interface_types” crates in the repository for this crate.
use abi_stable::{
erased_types::{
DeserializeDyn, ImplType, InterfaceType, SerializeImplType,
SerializeProxyType, TypeInfo,
},
external_types::{RawValueBox, RawValueRef},
impl_get_type_info,
prefix_type::{PrefixTypeTrait, WithMetadata},
sabi_extern_fn,
std_types::{RBox, RBoxError, RErr, ROk, RResult, RStr},
traits::IntoReprC,
type_level::bools::*,
DynTrait, StableAbi,
};
//////////////////////////////////
//// In interface crate /////
//////////////////////////////////
use serde::{Deserialize, Serialize};
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug, Clone, Serialize, Deserialize, PartialEq))]
pub struct FooInterface;
/// The state passed to most functions in the TextOpsMod module.
pub type FooInterfaceBox = DynTrait<'static, RBox<()>, FooInterface>;
/// First <ConcreteType as DeserializeImplType>::serialize_impl returns
/// a RawValueBox containing the serialized data,
/// then the returned RawValueBox is serialized.
impl<'s> SerializeProxyType<'s> for FooInterface {
type Proxy = RawValueBox;
}
impl<'borr> DeserializeDyn<'borr, FooInterfaceBox> for FooInterface {
type Proxy = RawValueRef<'borr>;
fn deserialize_dyn(
s: RawValueRef<'borr>,
) -> Result<FooInterfaceBox, RBoxError> {
MODULE.deserialize_foo()(s.get_rstr()).into_result()
}
}
// `#[sabi(kind(Prefix))]` declares this type as being a prefix-type,
// generating both of these types:<br>
//
// - Module_Prefix`:
// A struct with the fields up to (and including) the field with the
// `#[sabi(last_prefix_field)]` attribute.
//
// - Module_Ref`:
// An ffi-safe pointer to a `Module`, with methods to get `Module`'s fields.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(kind(Prefix))]
#[sabi(missing_field(panic))]
pub struct Module {
#[sabi(last_prefix_field)]
pub deserialize_foo:
extern "C" fn(s: RStr<'_>) -> RResult<FooInterfaceBox, RBoxError>,
}
// This is how ffi-safe pointers to non-generic prefix types are constructed
// at compile-time.
const MODULE: Module_Ref = {
const S: &WithMetadata<Module> =
&WithMetadata::new(PrefixTypeTrait::METADATA, Module { deserialize_foo });
Module_Ref(S.static_as_prefix())
};
/////////////////////////////////////////////////////////////////////////////////////////
//// In implementation crate (the one that gets compiled as a dynamic library) /////
/////////////////////////////////////////////////////////////////////////////////////////
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Foo {
name: String,
}
impl ImplType for Foo {
type Interface = FooInterface;
const INFO: &'static TypeInfo = impl_get_type_info! { Foo };
}
impl<'s> SerializeImplType<'s> for Foo {
type Interface = FooInterface;
fn serialize_impl(&'s self) -> Result<RawValueBox, RBoxError> {
match serde_json::to_string(self) {
Ok(v) => RawValueBox::try_from_string(v).map_err(RBoxError::new),
Err(e) => Err(RBoxError::new(e)),
}
}
}
#[sabi_extern_fn]
pub fn deserialize_foo(s: RStr<'_>) -> RResult<FooInterfaceBox, RBoxError> {
match serde_json::from_str::<Foo>(s.into()) {
Ok(x) => ROk(DynTrait::from_value(x)),
Err(e) => RErr(RBoxError::new(e)),
}
}
#[test]
fn testing_serialization_deserialization() {
let foo = Foo {
name: "nope".into(),
};
let object = DynTrait::from_value(foo.clone());
assert_eq!(
serde_json::from_str::<FooInterfaceBox>(
r##"
{
"name":"nope"
}
"##
)
.unwrap(),
object
);
assert_eq!(
serde_json::to_string(&object).unwrap(),
r##"{"name":"nope"}"##
);
}
Examples
In the Readme
The primary example using DynTrait<_>
is in the readme.
Readme is in the repository for this crate, crates.io, lib.rs.
Comparing DynTraits
This is only possible if the erased types don’t contain borrows,
and they are not constructed using DynTrait::from_borrowing_*
methods.
DynTraits wrapping different pointer types can be compared with each other, it simply uses the values’ implementation of PartialEq.
use abi_stable::{
erased_types::interfaces::PartialEqInterface,
std_types::{RArc, RBox},
DynTrait, RMut, RRef,
};
{
// `DynTrait`s constructed from `&` are `DynTrait<'_, RRef<'_, ()>, _>`
// since `&T` can't soundly be transmuted back and forth into `&()`
let left: DynTrait<'static, RRef<'_, ()>, PartialEqInterface> =
DynTrait::from_any_ptr(&100, PartialEqInterface);
let mut n100 = 100;
// `DynTrait`s constructed from `&mut` are `DynTrait<'_, RMut<'_, ()>, _>`
// since `&mut T` can't soundly be transmuted back and forth into `&mut ()`
let right: DynTrait<'static, RMut<'_, ()>, PartialEqInterface> =
DynTrait::from_any_ptr(&mut n100, PartialEqInterface);
assert_eq!(left, right);
}
{
let left: DynTrait<'static, RBox<()>, _> =
DynTrait::from_any_value(200, PartialEqInterface);
let right: DynTrait<'static, RArc<()>, _> =
DynTrait::from_any_ptr(RArc::new(200), PartialEqInterface);
assert_eq!(left, right);
}
Writing to a DynTrait
This is an example of using the write!()
macro with DynTrait.
use abi_stable::{erased_types::interfaces::FmtWriteInterface, DynTrait, RMut};
use std::fmt::Write;
let mut buffer = String::new();
let mut wrapped: DynTrait<'static, RMut<'_, ()>, FmtWriteInterface> =
DynTrait::from_any_ptr(&mut buffer, FmtWriteInterface);
write!(wrapped, "Foo").unwrap();
write!(wrapped, "Bar").unwrap();
write!(wrapped, "Baz").unwrap();
drop(wrapped);
assert_eq!(&buffer[..], "FooBarBaz");
Iteration
Using DynTrait
as an Iterator
and DoubleEndedIterator
.
use abi_stable::{erased_types::interfaces::DEIteratorInterface, DynTrait};
let mut wrapped = DynTrait::from_any_value(0..=10, DEIteratorInterface::NEW);
assert_eq!(
wrapped.by_ref().take(5).collect::<Vec<_>>(),
vec![0, 1, 2, 3, 4]
);
assert_eq!(wrapped.rev().collect::<Vec<_>>(), vec![10, 9, 8, 7, 6, 5]);
Making pointers compatible with DynTrait
To make pointers compatible with DynTrait, they must imlement the
abi_stable::pointer_trait::{
GetPointerKind
,
AsPtr
,
AsMutPtr
,
CanTransmuteElement
}
traits as shown in the example.
GetPointerKind
should generally be implemented with
type Kind =
PK_SmartPointer
.
The exception is in the case that it is a #[repr(transparent)]
wrapper around a RRef
/RMut
/*const T
/*mut T
/NonNull
,
in which case it should implement GetPointerKind
<Kind =
PK_Reference
>
(when it has shared reference semantics)
or GetPointerKind
<Kind =
PK_MutReference
>
(when it has mutable reference semantics).
Example
This is an example of a newtype wrapping an RBox
,
demonstrating that the pointer type doesn’t have to implement
the traits in the InterfaceType
, it’s the value it points to.
use abi_stable::DynTrait;
fn main() {
let lines = "line0\nline1\nline2";
let mut iter = NewtypeBox::new(lines.lines());
// The type annotation here is just to show the type, it's not necessary.
let mut wrapper: DynTrait<'_, NewtypeBox<()>, IteratorInterface> =
DynTrait::from_borrowing_ptr(iter, IteratorInterface);
// You can clone the DynTrait!
let clone = wrapper.clone();
assert_eq!(wrapper.next(), Some("line0"));
assert_eq!(wrapper.next(), Some("line1"));
assert_eq!(wrapper.next(), Some("line2"));
assert_eq!(wrapper.next(), None);
assert_eq!(
clone.rev().collect::<Vec<_>>(),
vec!["line2", "line1", "line0"],
)
}
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(
Sync,
Send,
Iterator,
DoubleEndedIterator,
Clone,
Debug
))]
pub struct IteratorInterface;
impl<'a> IteratorItem<'a> for IteratorInterface {
type Item = &'a str;
}
/////////////////////////////////////////
use std::ops::{Deref, DerefMut};
use abi_stable::{
erased_types::IteratorItem,
pointer_trait::{
AsMutPtr, AsPtr, CanTransmuteElement, GetPointerKind, PK_SmartPointer,
},
std_types::RBox,
type_level::bools::True,
InterfaceType, StableAbi,
};
#[repr(transparent)]
#[derive(Default, Clone, StableAbi)]
pub struct NewtypeBox<T> {
box_: RBox<T>,
}
impl<T> NewtypeBox<T> {
pub fn new(value: T) -> Self {
Self {
box_: RBox::new(value),
}
}
}
unsafe impl<T> GetPointerKind for NewtypeBox<T> {
// This is a smart pointer because `RBox` is one.
type Kind = PK_SmartPointer;
type PtrTarget = T;
}
// safety: Does not create an intermediate `&T` to get a pointer to `T`.
unsafe impl<T> AsPtr for NewtypeBox<T> {
fn as_ptr(&self) -> *const T {
self.box_.as_ptr()
}
}
// safety: Does not create an intermediate `&mut T` to get a pointer to `T`
unsafe impl<T> AsMutPtr for NewtypeBox<T> {
fn as_mut_ptr(&mut self) -> *mut T {
self.box_.as_mut_ptr()
}
}
// safety:
// NewtypeBox is safe to transmute, because RBox (the pointer type it wraps)
// is safe to transmute
unsafe impl<T, O> CanTransmuteElement<O> for NewtypeBox<T> {
type TransmutedPtr = NewtypeBox<O>;
unsafe fn transmute_element_(self) -> Self::TransmutedPtr {
let box_: RBox<O> = self.box_.transmute_element_();
NewtypeBox { box_ }
}
}
Implementations
sourceimpl DynTrait<'static, RRef<'static, ()>, ()>
impl DynTrait<'static, RRef<'static, ()>, ()>
sourcepub fn from_value<T>(object: T) -> DynTrait<'static, RBox<()>, T::Interface>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, RBox<()>, RBox<T>, <T as ImplType>::Interface>,
pub fn from_value<T>(object: T) -> DynTrait<'static, RBox<()>, T::Interface>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, RBox<()>, RBox<T>, <T as ImplType>::Interface>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a T: ImplType
.
Use this whenever possible instead of from_any_value
,
because it produces better error messages when unerasing the DynTrait<_>
Example
use abi_stable::{
erased_types::TypeInfo, std_types::RBox, DynTrait, ImplType, StableAbi,
};
fn main() {
let to: DynTrait<'static, RBox<()>, FooInterface> =
DynTrait::from_value(Foo(10u32));
assert_eq!(format!("{:?}", to), "Foo(10)");
}
#[repr(transparent)]
#[derive(Debug, StableAbi)]
struct Foo(u32);
impl ImplType for Foo {
type Interface = FooInterface;
const INFO: &'static TypeInfo = abi_stable::impl_get_type_info!(Foo);
}
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug))]
pub struct FooInterface;
sourcepub fn from_ptr<P, T>(
object: P
) -> DynTrait<'static, P::TransmutedPtr, T::Interface>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, P::TransmutedPtr, P, <T as ImplType>::Interface>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
pub fn from_ptr<P, T>(
object: P
) -> DynTrait<'static, P::TransmutedPtr, T::Interface>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, P::TransmutedPtr, P, <T as ImplType>::Interface>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a pointer to a T: ImplType
.
Use this whenever possible instead of from_any_ptr
,
because it produces better error messages when unerasing the DynTrait<_>
Example
use abi_stable::{
erased_types::TypeInfo,
std_types::{RArc, RBox},
DynTrait, ImplType, RMut, RRef, StableAbi,
};
fn main() {
// Constructing a DynTrait from a `&T`
{
// `DynTrait`s constructed from `&` are `DynTrait<'_, RRef<'_, ()>, _>`
// since `&T` can't soundly be transmuted back and forth into `&()`
let rref: DynTrait<'static, RRef<'_, ()>, FooInterface> =
DynTrait::from_ptr(&Foo(10u32));
assert_eq!(format!("{:?}", rref), "Foo(10)");
}
// Constructing a DynTrait from a `&mut T`
{
let mmut = &mut Foo(20u32);
// `DynTrait`s constructed from `&mut` are `DynTrait<'_, RMut<'_, ()>, _>`
// since `&mut T` can't soundly be transmuted back and forth into `&mut ()`
let rmut: DynTrait<'static, RMut<'_, ()>, FooInterface> =
DynTrait::from_ptr(mmut);
assert_eq!(format!("{:?}", rmut), "Foo(20)");
}
// Constructing a DynTrait from a `RBox<T>`
{
let boxed: DynTrait<'static, RBox<()>, FooInterface> =
DynTrait::from_ptr(RBox::new(Foo(30u32)));
assert_eq!(format!("{:?}", boxed), "Foo(30)");
}
// Constructing a DynTrait from an `RArc<T>`
{
let arc: DynTrait<'static, RArc<()>, FooInterface> =
DynTrait::from_ptr(RArc::new(Foo(30u32)));
assert_eq!(format!("{:?}", arc), "Foo(30)");
}
}
#[repr(transparent)]
#[derive(Debug, StableAbi)]
struct Foo(u32);
impl ImplType for Foo {
type Interface = FooInterface;
const INFO: &'static TypeInfo = abi_stable::impl_get_type_info!(Foo);
}
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug))]
pub struct FooInterface;
sourcepub fn from_any_value<T, I>(
object: T,
interface: I
) -> DynTrait<'static, RBox<()>, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'static,
I: InterfaceBound,
InterfaceFor<T, I, TD_CanDowncast>: GetVtable<'static, T, RBox<()>, RBox<T>, I>,
pub fn from_any_value<T, I>(
object: T,
interface: I
) -> DynTrait<'static, RBox<()>, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'static,
I: InterfaceBound,
InterfaceFor<T, I, TD_CanDowncast>: GetVtable<'static, T, RBox<()>, RBox<T>, I>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a type that doesn’t borrow anything.
Example
use abi_stable::{
erased_types::interfaces::DebugDisplayInterface, std_types::RBox, DynTrait,
};
// DebugDisplayInterface is `Debug + Display + Sync + Send`
let to: DynTrait<'static, RBox<()>, DebugDisplayInterface> =
DynTrait::from_any_value(3u8, DebugDisplayInterface);
assert_eq!(format!("{}", to), "3");
assert_eq!(format!("{:?}", to), "3");
sourcepub fn from_any_ptr<P, T, I>(
object: P,
_interface: I
) -> DynTrait<'static, P::TransmutedPtr, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
I: InterfaceBound,
T: 'static,
InterfaceFor<T, I, TD_CanDowncast>: GetVtable<'static, T, P::TransmutedPtr, P, I>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
pub fn from_any_ptr<P, T, I>(
object: P,
_interface: I
) -> DynTrait<'static, P::TransmutedPtr, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
I: InterfaceBound,
T: 'static,
InterfaceFor<T, I, TD_CanDowncast>: GetVtable<'static, T, P::TransmutedPtr, P, I>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a pointer to a
type that doesn’t borrow anything.
Example
use abi_stable::{
erased_types::interfaces::DebugDisplayInterface,
std_types::{RArc, RBox},
DynTrait, RMut, RRef,
};
// Constructing a DynTrait from a `&T`
{
// `DynTrait`s constructed from `&` are `DynTrait<'_, RRef<'_, ()>, _>`
// since `&T` can't soundly be transmuted back and forth into `&()`
let rref: DynTrait<'static, RRef<'_, ()>, DebugDisplayInterface> =
DynTrait::from_any_ptr(&21i32, DebugDisplayInterface);
assert_eq!(format!("{:?}", rref), "21");
assert_eq!(format!("{}", rref), "21");
}
// Constructing a DynTrait from a `&mut T`
{
let mmut = &mut "hello";
// `DynTrait`s constructed from `&mut` are `DynTrait<'_, RMut<'_, ()>, _>`
// since `&mut T` can't soundly be transmuted back and forth into `&mut ()`
let rmut: DynTrait<'static, RMut<'_, ()>, DebugDisplayInterface> =
DynTrait::from_any_ptr(mmut, DebugDisplayInterface);
assert_eq!(format!("{:?}", rmut), r#""hello""#);
assert_eq!(format!("{}", rmut), "hello");
}
// Constructing a DynTrait from a `RBox<T>`
{
let boxed: DynTrait<'static, RBox<()>, DebugDisplayInterface> =
DynTrait::from_any_ptr(RBox::new(false), DebugDisplayInterface);
assert_eq!(format!("{:?}", boxed), "false");
assert_eq!(format!("{}", boxed), "false");
}
// Constructing a DynTrait from an `RArc<T>`
{
let arc: DynTrait<'static, RArc<()>, DebugDisplayInterface> =
DynTrait::from_any_ptr(RArc::new(30u32), DebugDisplayInterface);
assert_eq!(format!("{:?}", arc), "30");
}
sourcepub fn from_borrowing_value<'borr, T, I>(
object: T,
interface: I
) -> DynTrait<'borr, RBox<()>, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TD_Opaque>: GetVtable<'borr, T, RBox<()>, RBox<T>, I>,
pub fn from_borrowing_value<'borr, T, I>(
object: T,
interface: I
) -> DynTrait<'borr, RBox<()>, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TD_Opaque>: GetVtable<'borr, T, RBox<()>, RBox<T>, I>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a value with a 'borr
borrow.
Cannot downcast the DynTrait afterwards.
Example
use abi_stable::{
erased_types::interfaces::DebugDisplayInterface, std_types::RBox, DynTrait,
};
// DebugDisplayInterface is `Debug + Display + Sync + Send`
let to: DynTrait<'static, RBox<()>, DebugDisplayInterface> =
DynTrait::from_borrowing_value(3u8, DebugDisplayInterface);
assert_eq!(format!("{}", to), "3");
assert_eq!(format!("{:?}", to), "3");
// `DynTrait`s constructed using the `from_borrowing_*` constructors
// can't be downcasted.
assert_eq!(to.downcast_as::<u8>().ok(), None);
sourcepub fn from_borrowing_ptr<'borr, P, T, I>(
object: P,
_interface: I
) -> DynTrait<'borr, P::TransmutedPtr, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TD_Opaque>: GetVtable<'borr, T, P::TransmutedPtr, P, I>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
pub fn from_borrowing_ptr<'borr, P, T, I>(
object: P,
_interface: I
) -> DynTrait<'borr, P::TransmutedPtr, I>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TD_Opaque>: GetVtable<'borr, T, P::TransmutedPtr, P, I>,
P: GetPointerKind<PtrTarget = T> + CanTransmuteElement<()>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs the DynTrait<_>
from a pointer to the erased type
with a 'borr
borrow.
Cannot downcast the DynTrait afterwards.
Example
use abi_stable::{
erased_types::interfaces::DebugDisplayInterface,
std_types::{RArc, RBox},
DynTrait, RMut, RRef,
};
// Constructing a DynTrait from a `&T`
{
// `DynTrait`s constructed from `&` are `DynTrait<'_, RRef<'_, ()>, _>`
// since `&T` can't soundly be transmuted back and forth into `&()`
let rref: DynTrait<'_, RRef<'_, ()>, DebugDisplayInterface> =
DynTrait::from_borrowing_ptr(&34i32, DebugDisplayInterface);
assert_eq!(format!("{:?}", rref), "34");
assert_eq!(format!("{}", rref), "34");
}
// Constructing a DynTrait from a `&mut T`
{
let mmut = &mut "world";
// `DynTrait`s constructed from `&mut` are `DynTrait<'_, RMut<'_, ()>, _>`
// since `&mut T` can't soundly be transmuted back and forth into `&mut ()`
let rmut: DynTrait<'_, RMut<'_, ()>, DebugDisplayInterface> =
DynTrait::from_borrowing_ptr(mmut, DebugDisplayInterface);
assert_eq!(format!("{:?}", rmut), r#""world""#);
assert_eq!(format!("{}", rmut), "world");
}
// Constructing a DynTrait from a `RBox<T>`
{
let boxed: DynTrait<'_, RBox<()>, DebugDisplayInterface> =
DynTrait::from_borrowing_ptr(RBox::new(true), DebugDisplayInterface);
assert_eq!(format!("{:?}", boxed), "true");
assert_eq!(format!("{}", boxed), "true");
}
// Constructing a DynTrait from an `RArc<T>`
{
let arc: DynTrait<'_, RArc<()>, DebugDisplayInterface> =
DynTrait::from_borrowing_ptr(RArc::new('a'), DebugDisplayInterface);
assert_eq!(format!("{:?}", arc), "'a'");
assert_eq!(format!("{}", arc), "a");
}
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: AsPtr<PtrTarget = ()>,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: AsPtr<PtrTarget = ()>,
sourcepub fn with_extra_value<OrigPtr, Downcasting>(
ptr: OrigPtr,
extra_value: EV
) -> DynTrait<'borr, P, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
OrigPtr: GetPointerKind,
OrigPtr::PtrTarget: 'borr,
I: InterfaceBound,
InterfaceFor<OrigPtr::PtrTarget, I, Downcasting>: GetVtable<'borr, OrigPtr::PtrTarget, P, OrigPtr, I>,
OrigPtr: CanTransmuteElement<(), TransmutedPtr = P>,
pub fn with_extra_value<OrigPtr, Downcasting>(
ptr: OrigPtr,
extra_value: EV
) -> DynTrait<'borr, P, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
OrigPtr: GetPointerKind,
OrigPtr::PtrTarget: 'borr,
I: InterfaceBound,
InterfaceFor<OrigPtr::PtrTarget, I, Downcasting>: GetVtable<'borr, OrigPtr::PtrTarget, P, OrigPtr, I>,
OrigPtr: CanTransmuteElement<(), TransmutedPtr = P>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Constructs an DynTrait from an erasable pointer and an extra value.
Example
use abi_stable::{
erased_types::{interfaces::DebugDisplayInterface, TD_Opaque},
DynTrait, RRef,
};
// DebugDisplayInterface is `Debug + Display + Sync + Send`
let to: DynTrait<'static, RRef<()>, DebugDisplayInterface, usize> =
DynTrait::with_extra_value::<_, TD_Opaque>(&55u8, 100usize);
assert_eq!(format!("{}", to), "55");
assert_eq!(format!("{:?}", to), "55");
assert_eq!(to.sabi_extra_value(), &100);
sourceimpl<'borr, 'a, I, EV> DynTrait<'borr, RRef<'a, ()>, I, EV>
impl<'borr, 'a, I, EV> DynTrait<'borr, RRef<'a, ()>, I, EV>
sourcepub const fn from_const<T, Downcasting>(
ptr: &'a T,
can_it_downcast: Downcasting,
vtable_for: VTableDT<'borr, T, RRef<'a, ()>, RRef<'a, T>, I, Downcasting>,
extra_value: EV
) -> Selfwhere
T: 'borr,
pub const fn from_const<T, Downcasting>(
ptr: &'a T,
can_it_downcast: Downcasting,
vtable_for: VTableDT<'borr, T, RRef<'a, ()>, RRef<'a, T>, I, Downcasting>,
extra_value: EV
) -> Selfwhere
T: 'borr,
This function allows constructing a DynTrait in a constant/static.
Parameters
ptr
:
This is generally constructed with RRef::new(&value)
RRef
is a reference-like type that can be erased inside a const fn
on stable Rust
(once it becomes possible to unsafely cast &T
to &()
inside a const fn
,
and the minimum Rust version is bumped, this type will be replaced with a reference)
can_it_downcast
can be either:
-
TD_CanDowncast
: Which allows the trait object to be downcasted, requires that the value implements any. -
TD_Opaque
: Which does not allow the trait object to be downcasted.
vtable_for
:
This is constructible with VTableDT::GET
.
VTableDT
wraps the vtable for a DynTrait
,
while keeping the original type and pointer type that it was constructed for,
allowing this function to be safe to call.
extra_value
:
This is used by #[sabi_trait]
trait objects to store their vtable inside DynTrait.
Example
use abi_stable::{
erased_types::{
interfaces::DebugDisplayInterface, DynTrait, TD_Opaque, VTableDT,
},
sabi_types::RRef,
};
static STRING: &str = "What the heck";
static DYN: DynTrait<'static, RRef<'static, ()>, DebugDisplayInterface, ()> =
DynTrait::from_const(&STRING, TD_Opaque, VTableDT::GET, ());
fn main() {
assert_eq!(format!("{}", DYN), format!("{}", STRING));
assert_eq!(format!("{:?}", DYN), format!("{:?}", STRING));
}
sourceimpl<P, I, EV> DynTrait<'static, P, I, EV>where
P: GetPointerKind,
impl<P, I, EV> DynTrait<'static, P, I, EV>where
P: GetPointerKind,
sourcepub fn sabi_is_same_type<Other, I2, EV2>(
&self,
other: &DynTrait<'static, Other, I2, EV2>
) -> boolwhere
I2: InterfaceBound,
Other: GetPointerKind,
pub fn sabi_is_same_type<Other, I2, EV2>(
&self,
other: &DynTrait<'static, Other, I2, EV2>
) -> boolwhere
I2: InterfaceBound,
Other: GetPointerKind,
Allows checking whether 2 DynTrait<_>
s have a value of the same type.
Notes:
-
Types from different dynamic libraries/executables are never considered equal.
-
DynTrait
s constructed usingDynTrait::from_borrowing_*
are never considered to wrap the same type.
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, PrefixRef<EV>>where
P: GetPointerKind,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, PrefixRef<EV>>where
P: GetPointerKind,
sourcepub fn sabi_et_vtable(&self) -> PrefixRef<EV>
pub fn sabi_et_vtable(&self) -> PrefixRef<EV>
A vtable used by #[sabi_trait]
derived trait objects.
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
sourcepub fn sabi_extra_value(&self) -> &EV
pub fn sabi_extra_value(&self) -> &EV
Gets access to the extra value that was stored in this DynTrait in the
with_extra_value
constructor.
Example
use abi_stable::{erased_types::TD_Opaque, DynTrait, RRef};
let to: DynTrait<'static, RRef<()>, (), char> =
DynTrait::with_extra_value::<_, TD_Opaque>(&55u8, 'Z');
assert_eq!(to.sabi_extra_value(), &'Z');
sourcepub fn sabi_object_address(&self) -> usizewhere
P: AsPtr,
pub fn sabi_object_address(&self) -> usizewhere
P: AsPtr,
Returns the address of the wrapped object.
Example
use abi_stable::{erased_types::TD_Opaque, DynTrait, RRef};
let reff = &55u8;
let to: DynTrait<'static, RRef<()>, ()> = DynTrait::from_any_ptr(reff, ());
assert_eq!(to.sabi_object_address(), reff as *const _ as usize);
sourcepub fn sabi_erased_ref(&self) -> RRef<'_, ErasedObject>where
P: AsPtr,
pub fn sabi_erased_ref(&self) -> RRef<'_, ErasedObject>where
P: AsPtr,
Gets a reference pointing to the erased object.
Example
use abi_stable::{std_types::RBox, DynTrait};
let to: DynTrait<'static, RBox<()>, ()> = DynTrait::from_any_value(66u8, ());
unsafe {
assert_eq!(to.sabi_erased_ref().transmute_into_ref::<u8>(), &66);
}
sourcepub fn sabi_erased_mut(&mut self) -> RMut<'_, ErasedObject>where
P: AsMutPtr,
pub fn sabi_erased_mut(&mut self) -> RMut<'_, ErasedObject>where
P: AsMutPtr,
Gets a mutable reference pointing to the erased object.
Example
use abi_stable::{std_types::RBox, DynTrait};
let mut to: DynTrait<'static, RBox<()>, ()> = DynTrait::from_any_value("hello", ());
unsafe {
assert_eq!(
to.sabi_erased_mut().transmute_into_mut::<&str>(),
&mut "hello"
);
}
sourcepub fn sabi_as_rref(&self) -> RRef<'_, ()>where
P: AsPtr,
pub fn sabi_as_rref(&self) -> RRef<'_, ()>where
P: AsPtr,
Gets an RRef
pointing to the erased object.
Example
use abi_stable::{std_types::RBox, DynTrait};
let to: DynTrait<'static, RBox<()>, ()> = DynTrait::from_any_value(66u8, ());
unsafe {
assert_eq!(to.sabi_as_rref().transmute_into_ref::<u8>(), &66);
}
sourcepub fn sabi_as_rmut(&mut self) -> RMut<'_, ()>where
P: AsMutPtr,
pub fn sabi_as_rmut(&mut self) -> RMut<'_, ()>where
P: AsMutPtr,
Gets an RMut
pointing to the erased object.
Example
use abi_stable::{std_types::RBox, DynTrait};
let mut to: DynTrait<'static, RBox<()>, ()> = DynTrait::from_any_value("hello", ());
unsafe {
assert_eq!(to.sabi_as_rmut().transmute_into_mut::<&str>(), &mut "hello");
}
sourcepub fn sabi_with_value<F, R>(self, f: F) -> Rwhere
P: OwnedPointer<PtrTarget = ()>,
F: FnOnce(MovePtr<'_, ()>) -> R,
pub fn sabi_with_value<F, R>(self, f: F) -> Rwhere
P: OwnedPointer<PtrTarget = ()>,
F: FnOnce(MovePtr<'_, ()>) -> R,
Calls the f
callback with an MovePtr
pointing to the erased object.
Example
use abi_stable::{
sabi_types::MovePtr,
std_types::{RBox, RString, RVec},
DynTrait,
};
let to: DynTrait<'static, RBox<()>, ()> =
DynTrait::from_any_value(RVec::<u8>::from_slice(b"foobarbaz"), ());
let string = to.sabi_with_value(|x| unsafe {
MovePtr::into_inner(MovePtr::transmute::<String>(x))
});
assert_eq!(string, "foobarbaz");
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
sourcepub fn downcast_into_impltype<T>(
self
) -> Result<P::TransmutedPtr, UneraseError<Self>>where
P: CanTransmuteElement<T>,
T: ImplType,
pub fn downcast_into_impltype<T>(
self
) -> Result<P::TransmutedPtr, UneraseError<Self>>where
P: CanTransmuteElement<T>,
T: ImplType,
Unwraps the DynTrait<_>
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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{
erased_types::TypeInfo,
std_types::{RArc, RBox},
DynTrait, ImplType, StableAbi,
};
{
fn to() -> DynTrait<'static, RBox<()>, FooInterface> {
DynTrait::from_value(Foo(b'A'))
}
assert_eq!(
to().downcast_into_impltype::<Foo<u8>>().ok(),
Some(RBox::new(Foo(b'A'))),
);
assert_eq!(to().downcast_into_impltype::<Foo<u16>>().ok(), None,);
}
{
fn to() -> DynTrait<'static, RArc<()>, FooInterface> {
DynTrait::from_ptr(RArc::new(Foo(b'B')))
}
assert_eq!(
to().downcast_into_impltype::<Foo<u8>>().ok(),
Some(RArc::new(Foo(b'B'))),
);
assert_eq!(to().downcast_into_impltype::<Foo<u16>>().ok(), None,);
}
#[repr(transparent)]
#[derive(Debug, StableAbi, PartialEq)]
struct Foo<T>(T);
impl<T: 'static> ImplType for Foo<T> {
type Interface = FooInterface;
const INFO: &'static TypeInfo = abi_stable::impl_get_type_info!(Foo<T>);
}
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug))]
pub struct FooInterface;
sourcepub fn downcast_as_impltype<T>(&self) -> Result<&T, UneraseError<&Self>>where
P: AsPtr + CanTransmuteElement<T>,
T: ImplType,
pub fn downcast_as_impltype<T>(&self) -> Result<&T, UneraseError<&Self>>where
P: AsPtr + CanTransmuteElement<T>,
T: ImplType,
Unwraps the DynTrait<_>
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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{
erased_types::TypeInfo, std_types::RArc, DynTrait, ImplType, RMut, RRef,
StableAbi,
};
{
let to: DynTrait<'static, RRef<'_, ()>, FooInterface> =
DynTrait::from_ptr(&Foo(9u8));
assert_eq!(to.downcast_as_impltype::<Foo<u8>>().ok(), Some(&Foo(9u8)));
assert_eq!(to.downcast_as_impltype::<Foo<u16>>().ok(), None);
}
{
let mut val = Foo(7u8);
let to: DynTrait<'static, RMut<'_, ()>, FooInterface> =
DynTrait::from_ptr(&mut val);
assert_eq!(to.downcast_as_impltype::<Foo<u8>>().ok(), Some(&Foo(7)));
assert_eq!(to.downcast_as_impltype::<Foo<u16>>().ok(), None);
}
{
let to: DynTrait<'static, RArc<()>, FooInterface> =
DynTrait::from_ptr(RArc::new(Foo(1u8)));
assert_eq!(to.downcast_as_impltype::<Foo<u8>>().ok(), Some(&Foo(1u8)));
assert_eq!(to.downcast_as_impltype::<Foo<u16>>().ok(), None);
}
#[repr(transparent)]
#[derive(Debug, StableAbi, PartialEq)]
struct Foo<T>(T);
impl<T: 'static> ImplType for Foo<T> {
type Interface = FooInterface;
const INFO: &'static TypeInfo = abi_stable::impl_get_type_info!(Foo<T>);
}
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug))]
pub struct FooInterface;
sourcepub fn downcast_as_mut_impltype<T>(
&mut self
) -> Result<&mut T, UneraseError<&mut Self>>where
P: AsMutPtr + CanTransmuteElement<T>,
T: ImplType,
pub fn downcast_as_mut_impltype<T>(
&mut self
) -> Result<&mut T, UneraseError<&mut Self>>where
P: AsMutPtr + CanTransmuteElement<T>,
T: ImplType,
Unwraps the DynTrait<_>
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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{
erased_types::TypeInfo, std_types::RBox, DynTrait, ImplType, RMut, StableAbi,
};
{
let mut val = Foo(7u8);
let mut to: DynTrait<'static, RMut<'_, ()>, FooInterface> =
DynTrait::from_ptr(&mut val);
assert_eq!(
to.downcast_as_mut_impltype::<Foo<u8>>().ok(),
Some(&mut Foo(7))
);
assert_eq!(to.downcast_as_mut_impltype::<Foo<u16>>().ok(), None);
}
{
let mut to: DynTrait<'static, RBox<()>, FooInterface> =
DynTrait::from_ptr(RBox::new(Foo(1u8)));
assert_eq!(
to.downcast_as_mut_impltype::<Foo<u8>>().ok(),
Some(&mut Foo(1u8))
);
assert_eq!(to.downcast_as_mut_impltype::<Foo<u16>>().ok(), None);
}
#[repr(transparent)]
#[derive(Debug, StableAbi, PartialEq)]
struct Foo<T>(T);
impl<T: 'static> ImplType for Foo<T> {
type Interface = FooInterface;
const INFO: &'static TypeInfo = abi_stable::impl_get_type_info!(Foo<T>);
}
/// An `InterfaceType` describing which traits are implemented by FooInterfaceBox.
#[repr(C)]
#[derive(StableAbi)]
#[sabi(impl_InterfaceType(Sync, Debug))]
pub struct FooInterface;
sourcepub fn downcast_into<T>(self) -> Result<P::TransmutedPtr, UneraseError<Self>>where
T: 'static,
P: CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
pub fn downcast_into<T>(self) -> Result<P::TransmutedPtr, UneraseError<Self>>where
T: 'static,
P: CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
Unwraps the DynTrait<_>
into a pointer of
the concrete type that it was constructed with.
T
is required to not borrow 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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{
std_types::{RArc, RBox},
DynTrait,
};
{
fn to() -> DynTrait<'static, RBox<()>, ()> {
DynTrait::from_any_value(b'A', ())
}
assert_eq!(to().downcast_into::<u8>().ok(), Some(RBox::new(b'A')));
assert_eq!(to().downcast_into::<u16>().ok(), None);
}
{
fn to() -> DynTrait<'static, RArc<()>, ()> {
DynTrait::from_any_ptr(RArc::new(b'B'), ())
}
assert_eq!(to().downcast_into::<u8>().ok(), Some(RArc::new(b'B')));
assert_eq!(to().downcast_into::<u16>().ok(), None);
}
sourcepub fn downcast_as<T>(&self) -> Result<&T, UneraseError<&Self>>where
T: 'static,
P: AsPtr + CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
pub fn downcast_as<T>(&self) -> Result<&T, UneraseError<&Self>>where
T: 'static,
P: AsPtr + CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
Unwraps the DynTrait<_>
into a reference of
the concrete type that it was constructed with.
T
is required to not borrow 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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{std_types::RArc, DynTrait, RMut, RRef};
{
let to: DynTrait<'static, RRef<'_, ()>, ()> = DynTrait::from_any_ptr(&9u8, ());
assert_eq!(to.downcast_as::<u8>().ok(), Some(&9u8));
assert_eq!(to.downcast_as::<u16>().ok(), None);
}
{
let mut val = 7u8;
let to: DynTrait<'static, RMut<'_, ()>, ()> =
DynTrait::from_any_ptr(&mut val, ());
assert_eq!(to.downcast_as::<u8>().ok(), Some(&7));
assert_eq!(to.downcast_as::<u16>().ok(), None);
}
{
let to: DynTrait<'static, RArc<()>, ()> =
DynTrait::from_any_ptr(RArc::new(1u8), ());
assert_eq!(to.downcast_as::<u8>().ok(), Some(&1u8));
assert_eq!(to.downcast_as::<u16>().ok(), None);
}
sourcepub fn downcast_as_mut<T>(&mut self) -> Result<&mut T, UneraseError<&mut Self>>where
P: AsMutPtr + CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
pub fn downcast_as_mut<T>(&mut self) -> Result<&mut T, UneraseError<&mut Self>>where
P: AsMutPtr + CanTransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TD_CanDowncast>: ImplType,
Unwraps the DynTrait<_>
into a mutable reference of
the concrete type that it was constructed with.
T
is required to not borrow 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
DynTrait<_>
was constructed. -
The DynTrait was constructed using a
from_borrowing_*
method -
T
is not the concrete type thisDynTrait<_>
was constructed with.
Example
use abi_stable::{std_types::RBox, DynTrait, RMut};
{
let mut val = 7u8;
let mut to: DynTrait<'static, RMut<'_, ()>, ()> =
DynTrait::from_any_ptr(&mut val, ());
assert_eq!(to.downcast_as_mut::<u8>().ok(), Some(&mut 7));
assert_eq!(to.downcast_as_mut::<u16>().ok(), None);
}
{
let mut to: DynTrait<'static, RBox<()>, ()> =
DynTrait::from_any_ptr(RBox::new(1u8), ());
assert_eq!(to.downcast_as_mut::<u8>().ok(), Some(&mut 1u8));
assert_eq!(to.downcast_as_mut::<u16>().ok(), None);
}
sourcepub unsafe fn unchecked_downcast_into<T>(self) -> P::TransmutedPtrwhere
P: AsPtr + CanTransmuteElement<T>,
pub unsafe fn unchecked_downcast_into<T>(self) -> P::TransmutedPtrwhere
P: AsPtr + CanTransmuteElement<T>,
Unwraps the DynTrait<_>
into a pointer to T,
without checking whether T
is the type that the DynTrait was constructed with.
Safety
You must check that T
is the type that DynTrait was constructed
with through other means.
Example
use abi_stable::{
std_types::{RArc, RBox},
DynTrait,
};
unsafe {
fn to() -> DynTrait<'static, RBox<()>, ()> {
DynTrait::from_any_value(b'A', ())
}
assert_eq!(to().unchecked_downcast_into::<u8>(), RBox::new(b'A'));
}
unsafe {
fn to() -> DynTrait<'static, RArc<()>, ()> {
DynTrait::from_any_ptr(RArc::new(b'B'), ())
}
assert_eq!(to().unchecked_downcast_into::<u8>(), RArc::new(b'B'));
}
sourcepub unsafe fn unchecked_downcast_as<T>(&self) -> &Twhere
P: AsPtr,
pub unsafe fn unchecked_downcast_as<T>(&self) -> &Twhere
P: AsPtr,
Unwraps the DynTrait<_>
into a reference to T,
without checking whether T
is the type that the DynTrait was constructed with.
Safety
You must check that T
is the type that DynTrait was constructed
with through other means.
Example
use abi_stable::{std_types::RArc, DynTrait, RMut, RRef};
unsafe {
let to: DynTrait<'static, RRef<'_, ()>, ()> = DynTrait::from_any_ptr(&9u8, ());
assert_eq!(to.unchecked_downcast_as::<u8>(), &9u8);
}
unsafe {
let mut val = 7u8;
let to: DynTrait<'static, RMut<'_, ()>, ()> =
DynTrait::from_any_ptr(&mut val, ());
assert_eq!(to.unchecked_downcast_as::<u8>(), &7);
}
unsafe {
let to: DynTrait<'static, RArc<()>, ()> =
DynTrait::from_any_ptr(RArc::new(1u8), ());
assert_eq!(to.unchecked_downcast_as::<u8>(), &1u8);
}
sourcepub unsafe fn unchecked_downcast_as_mut<T>(&mut self) -> &mut Twhere
P: AsMutPtr,
pub unsafe fn unchecked_downcast_as_mut<T>(&mut self) -> &mut Twhere
P: AsMutPtr,
Unwraps the DynTrait<_>
into a mutable reference to T,
without checking whether T
is the type that the DynTrait was constructed with.
Safety
You must check that T
is the type that DynTrait was constructed
with through other means.
Example
use abi_stable::{std_types::RBox, DynTrait, RMut};
unsafe {
let mut val = 7u8;
let mut to: DynTrait<'static, RMut<'_, ()>, ()> =
DynTrait::from_any_ptr(&mut val, ());
assert_eq!(to.unchecked_downcast_as_mut::<u8>(), &mut 7);
}
unsafe {
let mut to: DynTrait<'static, RBox<()>, ()> =
DynTrait::from_any_ptr(RBox::new(1u8), ());
assert_eq!(to.unchecked_downcast_as_mut::<u8>(), &mut 1u8);
}
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
I: InterfaceType,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
I: InterfaceType,
sourcepub fn reborrow<'re>(&'re self) -> DynTrait<'borr, RRef<'re, ()>, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
P: AsPtr<PtrTarget = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
pub fn reborrow<'re>(&'re self) -> DynTrait<'borr, RRef<'re, ()>, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
P: AsPtr<PtrTarget = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Creates a shared reborrow of this DynTrait.
The reborrowed DynTrait cannot use these methods:
- DynTrait::default
This is only callable if DynTrait
is either Send + Sync
or !Send + !Sync
.
Example
use abi_stable::{
erased_types::interfaces::DebugDisplayInterface,
std_types::RBox,
type_level::{impl_enum::Implemented, trait_marker},
DynTrait, InterfaceBound, RRef,
};
let to: DynTrait<'static, RBox<()>, DebugDisplayInterface> =
DynTrait::from_any_value(1337_u16, DebugDisplayInterface);
assert_eq!(debug_string(to.reborrow()), "1337");
fn debug_string<I>(to: DynTrait<'_, RRef<'_, ()>, I>) -> String
where
I: InterfaceBound<Debug = Implemented<trait_marker::Debug>>,
{
format!("{:?}", to)
}
sourcepub fn reborrow_mut<'re>(&'re mut self) -> DynTrait<'borr, RMut<'re, ()>, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
P: AsMutPtr<PtrTarget = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
pub fn reborrow_mut<'re>(&'re mut self) -> DynTrait<'borr, RMut<'re, ()>, I, EV>ⓘNotable traits for DynTrait<'borr, P, I, EV>impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
where
P: AsMutPtr<PtrTarget = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr, type Item = Item;impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
Creates a mutable reborrow of this DynTrait.
The reborrowed DynTrait cannot use these methods:
-
DynTrait::default
-
DynTrait::clone
This is only callable if DynTrait
is either Send + Sync
or !Send + !Sync
.
Example
use abi_stable::{
erased_types::interfaces::DEIteratorInterface, std_types::RBox, DynTrait,
};
let mut to = DynTrait::from_any_value(0_u8..=255, DEIteratorInterface::NEW);
assert_eq!(both_ends(to.reborrow_mut()), (Some(0), Some(255)));
assert_eq!(both_ends(to.reborrow_mut()), (Some(1), Some(254)));
assert_eq!(both_ends(to.reborrow_mut()), (Some(2), Some(253)));
assert_eq!(both_ends(to.reborrow_mut()), (Some(3), Some(252)));
fn both_ends<I>(mut to: I) -> (Option<I::Item>, Option<I::Item>)
where
I: DoubleEndedIterator,
{
(to.next(), to.next_back())
}
sourceimpl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
I: InterfaceBound + 'borr,
EV: 'borr,
P: AsPtr,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>where
I: InterfaceBound + 'borr,
EV: 'borr,
P: AsPtr,
sourcepub fn default(&self) -> Selfwhere
P: AsPtr + GetPointerKind<Kind = PK_SmartPointer>,
I: InterfaceType<Default = Implemented<Default>>,
EV: Copy,
pub fn default(&self) -> Selfwhere
P: AsPtr + GetPointerKind<Kind = PK_SmartPointer>,
I: InterfaceType<Default = Implemented<Default>>,
EV: Copy,
Constructs a DynTrait<P, I>
with the default value for P
.
Reborrowing
This cannot be called with a reborrowed DynTrait:
let object = DynTrait::from_any_value((), DefaultInterface);
let borrow = object.reborrow();
let _ = borrow.default();
let object = DynTrait::from_any_value((), DefaultInterface);
let borrow = object.reborrow_mut();
let _ = borrow.default();
Example
use abi_stable::{erased_types::interfaces::DebugDefEqInterface, DynTrait};
{
let object = DynTrait::from_any_value(true, DebugDefEqInterface);
assert_eq!(
object.default(),
DynTrait::from_any_value(false, DebugDefEqInterface)
);
}
{
let object = DynTrait::from_any_value(123u8, DebugDefEqInterface);
assert_eq!(
object.default(),
DynTrait::from_any_value(0u8, DebugDefEqInterface)
);
}
sourcepub fn serialize_into_proxy<'a>(&'a self) -> Result<I::ProxyType, RBoxError>where
P: AsPtr,
I: InterfaceType<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType<'a>,
pub fn serialize_into_proxy<'a>(&'a self) -> Result<I::ProxyType, RBoxError>where
P: AsPtr,
I: InterfaceType<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType<'a>,
It serializes a DynTrait<_>
into a string by using
<ConcreteType as SerializeImplType>::serialize_impl
.
sourcepub fn deserialize_from_proxy<'de>(proxy: I::Proxy) -> Result<Self, RBoxError>where
P: 'borr + AsPtr,
I: DeserializeDyn<'de, Self>,
pub fn deserialize_from_proxy<'de>(proxy: I::Proxy) -> Result<Self, RBoxError>where
P: 'borr + AsPtr,
I: DeserializeDyn<'de, Self>,
Deserializes a DynTrait<'borr, _>
from a proxy type, by using
<I as DeserializeDyn<'borr, Self>>::deserialize_dyn
.
sourceimpl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
sourcepub fn skip_eager(&mut self, n: usize)
pub fn skip_eager(&mut self, n: usize)
Eagerly skips n elements from the iterator.
This method is faster than using Iterator::skip
.
Example
let mut iter = 0..20;
let mut wrapped = DynTrait::from_any_ptr(&mut iter, IteratorInterface::NEW);
assert_eq!(wrapped.next(), Some(0));
wrapped.skip_eager(2);
assert_eq!(wrapped.next(), Some(3));
assert_eq!(wrapped.next(), Some(4));
assert_eq!(wrapped.next(), Some(5));
wrapped.skip_eager(2);
assert_eq!(wrapped.next(), Some(8));
assert_eq!(wrapped.next(), Some(9));
wrapped.skip_eager(9);
assert_eq!(wrapped.next(), Some(19));
assert_eq!(wrapped.next(), None);
sourcepub fn extending_rvec(&mut self, buffer: &mut RVec<Item>, taking: ROption<usize>)
pub fn extending_rvec(&mut self, buffer: &mut RVec<Item>, taking: ROption<usize>)
Extends the RVec<Item>
with the self
Iterator.
Extends buffer
with as many elements of the iterator as taking
specifies:
-
RNone: Yields all elements.Use this with care, since Iterators can be infinite.
-
RSome(n): Yields n elements.
Example
let mut wrapped = DynTrait::from_any_value(0.., IteratorInterface::NEW);
let mut buffer = vec![101, 102, 103].into_c();
wrapped.extending_rvec(&mut buffer, RSome(5));
assert_eq!(&buffer[..], &*vec![101, 102, 103, 0, 1, 2, 3, 4]);
assert_eq!(wrapped.next(), Some(5));
assert_eq!(wrapped.next(), Some(6));
assert_eq!(wrapped.next(), Some(7));
sourceimpl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>where
Self: Iterator<Item = Item>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>where
Self: Iterator<Item = Item>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
sourcepub fn nth_back_(&mut self, nth: usize) -> Option<Item>
pub fn nth_back_(&mut self, nth: usize) -> Option<Item>
Gets teh nth
element from the back of the iterator.
Example
use abi_stable::{erased_types::interfaces::DEIteratorCloneInterface, DynTrait};
let to = || DynTrait::from_any_value(7..=10, DEIteratorCloneInterface::NEW);
assert_eq!(to().nth_back_(0), Some(10));
assert_eq!(to().nth_back_(1), Some(9));
assert_eq!(to().nth_back_(2), Some(8));
assert_eq!(to().nth_back_(3), Some(7));
assert_eq!(to().nth_back_(4), None);
assert_eq!(to().nth_back_(5), None);
sourcepub fn extending_rvec_back(
&mut self,
buffer: &mut RVec<Item>,
taking: ROption<usize>
)
pub fn extending_rvec_back(
&mut self,
buffer: &mut RVec<Item>,
taking: ROption<usize>
)
Extends the RVec<Item>
with the back of the self
DoubleEndedIterator.
Extends buffer
with as many elements of the iterator as taking
specifies:
-
RNone: Yields all elements.Use this with care, since Iterators can be infinite.
-
RSome(n): Yields n elements.
Example
let mut wrapped = DynTrait::from_any_value(0..=3, DEIteratorInterface::NEW);
let mut buffer = vec![101, 102, 103].into_c();
wrapped.extending_rvec_back(&mut buffer, RNone);
assert_eq!(&buffer[..], &*vec![101, 102, 103, 3, 2, 1, 0])
Trait Implementations
sourceimpl<'borr, P, I, EV> BufRead for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>, IoBufRead = Implemented<IoBufRead>>,
impl<'borr, P, I, EV> BufRead for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>, IoBufRead = Implemented<IoBufRead>>,
sourcefn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
sourcefn consume(&mut self, amount: usize)
fn consume(&mut self, amount: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresourcefn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Read
has any data left to be read. Read more1.0.0 · sourcefn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
1.0.0 · sourcefn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA
byte) is reached, and append
them to the provided buffer. You do not need to clear the buffer before
appending. Read moresourceimpl<'borr, P, I, EV> Clone for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound,
Self: CloneImpl<<P as GetPointerKind>::Kind>,
impl<'borr, P, I, EV> Clone for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound,
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.
DynTrait does not implement Clone if P ==RMut<'_, ()>
:
let mut object = DynTrait::from_any_value((),());
let borrow = object.reborrow_mut();
let _ = borrow.clone();
sourceimpl<'borr, P, I, EV> Debug for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Debug = Implemented<Debug>>,
impl<'borr, P, I, EV> Debug for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Debug = Implemented<Debug>>,
sourceimpl<'de, 'borr: 'de, P, I, EV> Deserialize<'de> for DynTrait<'borr, P, I, EV>where
EV: 'borr,
P: AsPtr + 'borr,
I: InterfaceBound + 'borr,
I: DeserializeDyn<'de, Self>,
<I as DeserializeDyn<'de, Self>>::Proxy: Deserialize<'de>,
impl<'de, 'borr: 'de, P, I, EV> Deserialize<'de> for DynTrait<'borr, P, I, EV>where
EV: 'borr,
P: AsPtr + 'borr,
I: InterfaceBound + 'borr,
I: DeserializeDyn<'de, Self>,
<I as DeserializeDyn<'de, Self>>::Proxy: Deserialize<'de>,
First it Deserializes a string, then it deserializes into a
DynTrait<_>
, by using <I as DeserializeOwnedInterface>::deserialize_impl
.
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
sourceimpl<'borr, P, I, EV> Display for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Display = Implemented<Display>>,
impl<'borr, P, I, EV> Display for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Display = Implemented<Display>>,
sourceimpl<'borr, P, I, Item, EV> DoubleEndedIterator for DynTrait<'borr, P, I, EV>where
Self: Iterator<Item = Item>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
impl<'borr, P, I, Item, EV> DoubleEndedIterator for DynTrait<'borr, P, I, EV>where
Self: Iterator<Item = Item>,
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
sourcefn next_back(&mut self) -> Option<Item>
fn next_back(&mut self) -> Option<Item>
sourcefn advance_back_by(&mut self, n: usize) -> Result<(), usize>
fn advance_back_by(&mut self, n: usize) -> Result<(), usize>
iter_advance_by
)n
elements. Read more1.37.0 · sourcefn nth_back(&mut self, n: usize) -> Option<Self::Item>
fn nth_back(&mut self, n: usize) -> Option<Self::Item>
n
th element from the end of the iterator. Read more1.27.0 · sourcefn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
Iterator::try_fold()
: it takes
elements starting from the back of the iterator. Read moresourceimpl<'borr, P, I, EV> Drop for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
impl<'borr, P, I, EV> Drop for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
sourceimpl<'borr, P, I, EV> DynTraitBound<'borr> for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
I: InterfaceBound,
impl<'borr, P, I, EV> DynTraitBound<'borr> for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
I: InterfaceBound,
type Interface = I
sourceimpl<'borr, P, I, EV> Error for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,
impl<'borr, P, I, EV> Error for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,
1.30.0 · sourcefn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · sourcefn description(&self) -> &str
fn description(&self) -> &str
sourceimpl<'borr, P, I, EV> GetStaticEquivalent_ for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
EV: __StableAbi,
I: InterfaceBound,
VTable_Ref<'borr, P, I>: StableAbi,
impl<'borr, P, I, EV> GetStaticEquivalent_ for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
EV: __StableAbi,
I: InterfaceBound,
VTable_Ref<'borr, P, I>: StableAbi,
type StaticEquivalent = _static_DynTrait<'static, <P as GetStaticEquivalent_>::StaticEquivalent, <I as GetStaticEquivalent_>::StaticEquivalent, <EV as GetStaticEquivalent_>::StaticEquivalent>
sourceimpl<'borr, P, I, EV> Hash for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Hash = Implemented<Hash>>,
impl<'borr, P, I, EV> Hash for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Hash = Implemented<Hash>>,
sourceimpl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
type Item = Item
type Item = Item
sourcefn nth(&mut self, nth: usize) -> Option<Item>
fn nth(&mut self, nth: usize) -> Option<Item>
n
th element of the iterator. Read moresourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
sourcefn count(self) -> usize
fn count(self) -> usize
sourcefn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
iter_next_chunk
)N
values. Read moresourcefn advance_by(&mut self, n: usize) -> Result<(), usize>
fn advance_by(&mut self, n: usize) -> Result<(), usize>
iter_advance_by
)n
elements. Read more1.28.0 · sourcefn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
1.0.0 · sourcefn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator<Item = Self::Item>,
1.0.0 · sourcefn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
sourcefn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where
Self: Sized,
G: FnMut() -> Self::Item,
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where
Self: Sized,
G: FnMut() -> Self::Item,
iter_intersperse
)separator
between adjacent items of the original iterator. Read more1.0.0 · sourcefn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
1.21.0 · sourcefn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
1.0.0 · sourcefn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.0.0 · sourcefn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
1.0.0 · sourcefn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
1.0.0 · sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.0.0 · sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.57.0 · sourcefn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
1.0.0 · sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n
elements. Read more1.0.0 · sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n
elements, or fewer
if the underlying iterator ends sooner. Read more1.0.0 · sourcefn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
1.0.0 · sourcefn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
1.0.0 · sourcefn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
1.0.0 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
1.0.0 · sourcefn collect<B>(self) -> Bwhere
B: FromIterator<Self::Item>,
Self: Sized,
fn collect<B>(self) -> Bwhere
B: FromIterator<Self::Item>,
Self: Sized,
sourcefn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
iter_collect_into
)1.0.0 · sourcefn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
fn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
sourcefn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
iter_is_partitioned
)true
precede all those that return false
. Read more1.27.0 · sourcefn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
1.27.0 · sourcefn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
fn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
1.0.0 · sourcefn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
1.51.0 · sourcefn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
fn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
sourcefn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
iterator_try_reduce
)1.0.0 · sourcefn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
1.0.0 · sourcefn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
1.0.0 · sourcefn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.30.0 · sourcefn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
sourcefn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
try_find
)1.0.0 · sourcefn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
1.6.0 · sourcefn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
1.15.0 · sourcefn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.6.0 · sourcefn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
1.15.0 · sourcefn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.0.0 · sourcefn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
1.36.0 · sourcefn copied<'a, T>(self) -> Copied<Self>where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
fn copied<'a, T>(self) -> Copied<Self>where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
1.0.0 · sourcefn cloned<'a, T>(self) -> Cloned<Self>where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
fn cloned<'a, T>(self) -> Cloned<Self>where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
sourcefn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
iter_array_chunks
)N
elements of the iterator at a time. Read more1.11.0 · sourcefn sum<S>(self) -> Swhere
Self: Sized,
S: Sum<Self::Item>,
fn sum<S>(self) -> Swhere
Self: Sized,
S: Sum<Self::Item>,
1.11.0 · sourcefn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
fn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
sourcefn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · sourcefn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
sourcefn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · sourcefn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
sourcefn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
iter_order_by
)1.5.0 · sourcefn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
1.5.0 · sourcefn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
less than those of another. Read more1.5.0 · sourcefn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
less or equal to those of another. Read more1.5.0 · sourcefn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
greater than those of another. Read more1.5.0 · sourcefn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
greater than or equal to those of another. Read moresourcefn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
fn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
is_sorted
)sourcefn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
is_sorted
)sourceimpl<P, I, EV> Ord for DynTrait<'static, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Ord = Implemented<Ord>>,
Self: PartialOrd + Eq,
impl<P, I, EV> Ord for DynTrait<'static, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Ord = Implemented<Ord>>,
Self: PartialOrd + Eq,
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl<P, P2, I, EV, EV2> PartialEq<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>where
P: AsPtr,
P2: AsPtr,
I: InterfaceBound<PartialEq = Implemented<PartialEq>>,
impl<P, P2, I, EV, EV2> PartialEq<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>where
P: AsPtr,
P2: AsPtr,
I: InterfaceBound<PartialEq = Implemented<PartialEq>>,
sourceimpl<P, P2, I, EV, EV2> PartialOrd<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>where
P: AsPtr,
P2: AsPtr,
I: InterfaceBound<PartialOrd = Implemented<PartialOrd>>,
Self: PartialEq<DynTrait<'static, P2, I, EV2>>,
impl<P, P2, I, EV, EV2> PartialOrd<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>where
P: AsPtr,
P2: AsPtr,
I: InterfaceBound<PartialOrd = Implemented<PartialOrd>>,
Self: PartialEq<DynTrait<'static, P2, I, EV2>>,
sourcefn partial_cmp(&self, other: &DynTrait<'static, P2, I, EV2>) -> Option<Ordering>
fn partial_cmp(&self, other: &DynTrait<'static, P2, I, EV2>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresourceimpl<'borr, P, I, EV> Seek for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoSeek = Implemented<IoSeek>>,
impl<'borr, P, I, EV> Seek for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoSeek = Implemented<IoSeek>>,
sourcefn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · sourcefn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
sourceimpl<'borr, P, I, EV> Serialize for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType<'borr>,
I::ProxyType: Serialize,
impl<'borr, P, I, EV> Serialize for DynTrait<'borr, P, I, EV>where
P: AsPtr,
I: InterfaceBound<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType<'borr>,
I::ProxyType: Serialize,
First it serializes a DynTrait<_>
into a string by using
sourceimpl<'borr, P, I, EV> StableAbi for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
EV: __StableAbi,
I: InterfaceBound,
VTable_Ref<'borr, P, I>: StableAbi,
impl<'borr, P, I, EV> StableAbi for DynTrait<'borr, P, I, EV>where
P: GetPointerKind,
P: __StableAbi,
I: __StableAbi,
EV: __StableAbi,
I: InterfaceBound,
VTable_Ref<'borr, P, I>: StableAbi,
type IsNonZeroType = False
type IsNonZeroType = False
sourceconst LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
sourceconst ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.sourceimpl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<FmtWrite = Implemented<FmtWrite>>,
impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<FmtWrite = Implemented<FmtWrite>>,
sourceimpl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,
impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>where
P: AsMutPtr,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)impl<P, I, EV> Eq for DynTrait<'static, P, I, EV>where
Self: PartialEq,
P: AsPtr,
I: InterfaceBound<Eq = Implemented<Eq>>,
impl<'borr, P, I, EV> Send for DynTrait<'borr, P, I, EV>where
P: Send + GetPointerKind,
I: InterfaceBound<Send = Implemented<Send>>,
impl<'borr, P, I, EV> Sync for DynTrait<'borr, P, I, EV>where
P: Sync + GetPointerKind,
I: InterfaceBound<Sync = Implemented<Sync>>,
Auto Trait Implementations
impl<'borr, P, I, EV> RefUnwindSafe for DynTrait<'borr, P, I, EV>where
EV: RefUnwindSafe,
P: RefUnwindSafe,
impl<'borr, P, I, EV> Unpin for DynTrait<'borr, P, I, EV>where
EV: Unpin,
P: Unpin,
impl<'borr, P, I, EV> UnwindSafe for DynTrait<'borr, P, I, EV>where
EV: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<'a, T> BorrowOwned<'a> for Twhere
T: 'a + Clone,
impl<'a, T> BorrowOwned<'a> for Twhere
T: 'a + Clone,
type ROwned = T
type ROwned = T
RCow::Owned
fn r_borrow(
this: &'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
fn r_to_owned(
this: <T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
fn deref_borrowed(this: &<T as BorrowOwned<'a>>::RBorrowed) -> &T
fn deref_owned(this: &<T as BorrowOwned<'a>>::ROwned) -> &T
fn from_cow_borrow(this: &'a T) -> <T as BorrowOwned<'a>>::RBorrowed
fn from_cow_owned(this: <T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
fn into_cow_borrow(this: <T as BorrowOwned<'a>>::RBorrowed) -> &'a T
fn into_cow_owned(this: <T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
sourceimpl<T> GetWithMetadata for T
impl<T> GetWithMetadata for T
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
WithMetadata_<Self, Self>
sourceimpl<I> IntoIterator for Iwhere
I: Iterator,
impl<I> IntoIterator for Iwhere
I: Iterator,
sourceimpl<I> IteratorExt for Iwhere
I: Iterator + ?Sized,
impl<I> IteratorExt for Iwhere
I: Iterator + ?Sized,
sourcefn extending<C>(self, extend: &mut C)where
Self: Sized,
C: Extend<Self::Item>,
fn extending<C>(self, extend: &mut C)where
Self: Sized,
C: Extend<Self::Item>,
sourcefn collect_into<C>(self, extend: C) -> Cwhere
Self: Sized,
C: Extend<Self::Item>,
fn collect_into<C>(self, extend: C) -> Cwhere
Self: Sized,
C: Extend<Self::Item>,
sourcefn replace_nth(self, nth: usize, with: Self::Item) -> ReplaceNth<Self>where
Self: Sized,
fn replace_nth(self, nth: usize, with: Self::Item) -> ReplaceNth<Self>where
Self: Sized,
sourceimpl<S> ROExtAcc for S
impl<S> ROExtAcc for S
sourcefn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moresourcefn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moresourcefn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moresourcefn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moresourceimpl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
sourcefn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresourcefn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)
fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)
sourcefn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
sourceimpl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
sourcefn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresourcefn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)
fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)
sourcefn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
sourceimpl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
sourcefn piped<F, U>(self, f: F) -> Uwhere
F: FnOnce(Self) -> U,
Self: Sized,
fn piped<F, U>(self, f: F) -> Uwhere
F: FnOnce(Self) -> U,
Self: Sized,
sourcefn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moresourcefn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read moresourcefn mutated<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut Self),
Self: Sized,
fn mutated<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut Self),
Self: Sized,
sourcefn observe<F>(self, f: F) -> Selfwhere
F: FnOnce(&Self),
Self: Sized,
fn observe<F>(self, f: F) -> Selfwhere
F: FnOnce(&Self),
Self: Sized,
sourcefn as_ref_<T>(&self) -> &Twhere
Self: AsRef<T>,
T: ?Sized,
fn as_ref_<T>(&self) -> &Twhere
Self: AsRef<T>,
T: ?Sized,
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read moresourceimpl<This> TransmuteElement for Thiswhere
This: ?Sized,
impl<This> TransmuteElement for Thiswhere
This: ?Sized,
sourceunsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtrwhere
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtrwhere
Self: CanTransmuteElement<T>,
sourceimpl<T> TypeIdentity for Twhere
T: ?Sized,
impl<T> TypeIdentity for Twhere
T: ?Sized,
type Type = T
type Type = T
Self
.