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 implements AsPtr.

  • Interface is an InterfaceType, which describes what traits are required when constructing the 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 'static value.

  • from_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:

Deconstruction

DynTrait<_> can then be unwrapped into a concrete type, within the same dynamic library/executable that constructed it, using these (fallible) conversion methods:

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.

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.

Serialization/Deserialization

The DeserializeDyn and SerializeType demonstrate how DynTrait can be de/serialized.

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_ptr(&100);

    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_ptr(&mut n100).interface(PartialEqInterface);

    assert_eq!(left, right);
}
{
    let left: DynTrait<'static, RBox<()>, PartialEqInterface> =
        DynTrait::from_value(200);

    let right: DynTrait<'static, RArc<()>, _> =
        DynTrait::from_ptr(RArc::new(200)).interface(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_ptr(&mut buffer);

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_value(0..=10).interface(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);

    // 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§

source§

impl<I> DynTrait<'static, RBox<()>, I>

source

pub fn from_value<T>(object: T) -> Self
where T: 'static, VTable_Ref<'static, RBox<()>, I>: MakeVTable<'static, T, RBox<T>, TD_CanDowncast>,

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_value(3u8);

assert_eq!(format!("{}", to), "3");
assert_eq!(format!("{:?}", to), "3");
source§

impl<P, I> DynTrait<'static, P, I>
where P: GetPointerKind,

source

pub fn from_ptr<OrigPtr>(object: OrigPtr) -> Self
where OrigPtr: GetPointerKind + CanTransmuteElement<(), TransmutedPtr = P>, OrigPtr::PtrTarget: 'static, VTable_Ref<'static, P, I>: MakeVTable<'static, OrigPtr::PtrTarget, OrigPtr, TD_CanDowncast>,

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_ptr(&21i32);

    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_ptr(mmut).interface(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_ptr(RBox::new(false));

    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_ptr(RArc::new(30u32)).interface(DebugDisplayInterface);

    assert_eq!(format!("{:?}", arc), "30");
}
source§

impl<'borr, I> DynTrait<'borr, RBox<()>, I>

source

pub fn from_borrowing_value<T>(object: T) -> Self
where T: 'borr, VTable_Ref<'borr, RBox<()>, I>: MakeVTable<'borr, T, RBox<T>, TD_Opaque>,

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);

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);
source§

impl<'borr, P, I> DynTrait<'borr, P, I>
where P: GetPointerKind,

source

pub fn from_borrowing_ptr<OrigPtr>(object: OrigPtr) -> Self
where OrigPtr: GetPointerKind + 'borr + CanTransmuteElement<(), TransmutedPtr = P>, OrigPtr::PtrTarget: 'borr, VTable_Ref<'borr, P, I>: MakeVTable<'borr, OrigPtr::PtrTarget, OrigPtr, TD_Opaque>,

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);

    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).interface(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));

    assert_eq!(format!("{:?}", boxed), "true");
    assert_eq!(format!("{}", boxed), "true");
}
// Constructing a DynTrait from an `RArc<T>`
{
    let arc: DynTrait<'_, RArc<()>, _> =
        DynTrait::from_borrowing_ptr(RArc::new('a')).interface(DebugDisplayInterface);

    assert_eq!(format!("{:?}", arc), "'a'");
    assert_eq!(format!("{}", arc), "a");
}
source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
where P: AsPtr<PtrTarget = ()>,

source

pub fn with_extra_value<OrigPtr, Downcasting>( ptr: OrigPtr, extra_value: EV ) -> DynTrait<'borr, P, I, EV>
where OrigPtr: GetPointerKind + CanTransmuteElement<(), TransmutedPtr = P>, OrigPtr::PtrTarget: 'borr, VTable_Ref<'borr, P, I>: MakeVTable<'borr, OrigPtr::PtrTarget, OrigPtr, Downcasting>,

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);
source§

impl<'borr, 'a, I, EV> DynTrait<'borr, RRef<'a, ()>, I, EV>

source

pub const fn from_const<T, Downcasting>( ptr: &'a T, can_it_downcast: Downcasting, extra_value: EV ) -> Self
where VTable_Ref<'borr, RRef<'a, ()>, I>: MakeVTable<'borr, T, &'a T, Downcasting>, T: 'borr,

This function allows constructing a DynTrait in a constant/static.

Parameters

ptr: a reference to the value.


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.


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,
    },
    sabi_types::RRef,
};

static STRING: &str = "What the heck";

static DYN: DynTrait<'static, RRef<'static, ()>, DebugDisplayInterface, ()> =
    DynTrait::from_const(&STRING, TD_Opaque, ());

fn main() {
    assert_eq!(format!("{}", DYN), format!("{}", STRING));
    assert_eq!(format!("{:?}", DYN), format!("{:?}", STRING));
}
source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
where P: GetPointerKind,

source

pub const fn interface(self, _interface: I) -> Self
where I: InterfaceType,

For inferring the I type parameter.

source§

impl<P, I, EV> DynTrait<'static, P, I, EV>
where P: GetPointerKind,

source

pub fn sabi_is_same_type<Other, I2, EV2>( &self, other: &DynTrait<'static, Other, I2, EV2> ) -> bool
where I2: InterfaceType, 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.

  • DynTraits constructed using DynTrait::from_borrowing_* are never considered to wrap the same type.

source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, PrefixRef<EV>>
where P: GetPointerKind,

source

pub const fn sabi_et_vtable(&self) -> PrefixRef<EV>

A vtable used by #[sabi_trait] derived trait objects.

source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
where P: GetPointerKind,

source

pub const 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');
source

pub fn sabi_object_address(&self) -> usize
where 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_ptr(reff);

assert_eq!(to.sabi_object_address(), reff as *const _ as usize);
source

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_value(66u8);

unsafe {
    assert_eq!(to.sabi_erased_ref().transmute_into_ref::<u8>(), &66);
}
source

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_value("hello");

unsafe {
    assert_eq!(
        to.sabi_erased_mut().transmute_into_mut::<&str>(),
        &mut "hello"
    );
}
source

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_value(66u8);

unsafe {
    assert_eq!(to.sabi_as_rref().transmute_into_ref::<u8>(), &66);
}
source

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_value("hello");

unsafe {
    assert_eq!(to.sabi_as_rmut().transmute_into_mut::<&str>(), &mut "hello");
}
source

pub fn sabi_with_value<F, R>(self, f: F) -> R
where 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_value(RString::from("foobarbaz"));

let string = to.sabi_with_value(|x| {
    // SAFETY: the erased object is an RString constructed in the current binary.
    unsafe {
        MovePtr::into_inner(MovePtr::transmute::<RString>(x))
    }
});

assert_eq!(string, "foobarbaz");
source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
where P: GetPointerKind,

source

pub fn downcast_into<T>(self) -> Result<P::TransmutedPtr, UneraseError<Self>>
where T: 'static, P: CanTransmuteElement<T>,

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 this DynTrait<_> was constructed with.

Example
use abi_stable::{
    std_types::{RArc, RBox},
    DynTrait,
};

{
    fn to() -> DynTrait<'static, RBox<()>, ()> {
        DynTrait::from_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_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);
}
source

pub fn downcast_as<T>(&self) -> Result<&T, UneraseError<&Self>>
where T: 'static, P: AsPtr,

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 this DynTrait<_> was constructed with.

Example
use abi_stable::{std_types::RArc, DynTrait, RMut, RRef};

{
    let to: DynTrait<'static, RRef<'_, ()>, ()> = DynTrait::from_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_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_ptr(RArc::new(1u8));

    assert_eq!(to.downcast_as::<u8>().ok(), Some(&1u8));
    assert_eq!(to.downcast_as::<u16>().ok(), None);
}
source

pub fn downcast_as_mut<T>(&mut self) -> Result<&mut T, UneraseError<&mut Self>>
where T: 'static, P: AsMutPtr,

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 this DynTrait<_> was constructed with.

Example
use abi_stable::{std_types::RBox, DynTrait, RMut};

{
    let mut val = 7u8;

    let mut to: DynTrait<'static, RMut<'_, ()>, ()> =
        DynTrait::from_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_ptr(RBox::new(1u8));

    assert_eq!(to.downcast_as_mut::<u8>().ok(), Some(&mut 1u8));
    assert_eq!(to.downcast_as_mut::<u16>().ok(), None);
}
source

pub unsafe fn unchecked_downcast_into<T>(self) -> P::TransmutedPtr
where 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_value(b'A')
    }

    assert_eq!(to().unchecked_downcast_into::<u8>(), RBox::new(b'A'));
}
unsafe {
    fn to() -> DynTrait<'static, RArc<()>, ()> {
        DynTrait::from_ptr(RArc::new(b'B'))
    }

    assert_eq!(to().unchecked_downcast_into::<u8>(), RArc::new(b'B'));
}
source

pub unsafe fn unchecked_downcast_as<T>(&self) -> &T
where 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_ptr(&9u8);

    assert_eq!(to.unchecked_downcast_as::<u8>(), &9u8);
}
unsafe {
    let mut val = 7u8;

    let to: DynTrait<'static, RMut<'_, ()>, ()> =
        DynTrait::from_ptr(&mut val);

    assert_eq!(to.unchecked_downcast_as::<u8>(), &7);
}
unsafe {
    let to: DynTrait<'static, RArc<()>, ()> =
        DynTrait::from_ptr(RArc::new(1u8));

    assert_eq!(to.unchecked_downcast_as::<u8>(), &1u8);
}
source

pub unsafe fn unchecked_downcast_as_mut<T>(&mut self) -> &mut T
where 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_ptr(&mut val);

    assert_eq!(to.unchecked_downcast_as_mut::<u8>(), &mut 7);
}
unsafe {
    let mut to: DynTrait<'static, RBox<()>, ()> =
        DynTrait::from_ptr(RBox::new(1u8));

    assert_eq!(to.unchecked_downcast_as_mut::<u8>(), &mut 1u8);
}
source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>

source

pub fn reborrow<'re>(&'re self) -> DynTrait<'borr, RRef<'re, ()>, I, EV>
where P: AsPtr<PtrTarget = ()>, PrivStruct: ReborrowBounds<I::Send, I::Sync>, EV: Copy,

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, InterfaceType, RRef,
};

let to: DynTrait<'static, RBox<()>, DebugDisplayInterface> =
    DynTrait::from_value(1337_u16);

assert_eq!(debug_string(to.reborrow()), "1337");

fn debug_string<I>(to: DynTrait<'_, RRef<'_, ()>, I>) -> String
where
    I: InterfaceType<Debug = Implemented<trait_marker::Debug>>,
{
    format!("{:?}", to)
}
source

pub fn reborrow_mut<'re>(&'re mut self) -> DynTrait<'borr, RMut<'re, ()>, I, EV>
where P: AsMutPtr<PtrTarget = ()>, PrivStruct: ReborrowBounds<I::Send, I::Sync>, EV: Copy,

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_value(0_u8..=255).interface(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())
}
source§

impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
where I: InterfaceType + 'borr, EV: 'borr, P: AsPtr,

source

pub fn default(&self) -> Self
where 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_value(()).interface(DefaultInterface);
let borrow = object.reborrow();
let _ = borrow.default();
let object = DynTrait::from_value(()).interface(DefaultInterface);
let borrow = object.reborrow_mut();
let _ = borrow.default();
Example
use abi_stable::{erased_types::interfaces::DebugDefEqInterface, DynTrait};

{
    let object = DynTrait::from_value(true).interface(DebugDefEqInterface);

    assert_eq!(
        object.default(),
        DynTrait::from_value(false).interface(DebugDefEqInterface)
    );
}
{
    let object = DynTrait::from_value(123u8).interface(DebugDefEqInterface);

    assert_eq!(
        object.default(),
        DynTrait::from_value(0u8).interface(DebugDefEqInterface)
    );
}
source

pub fn serialize_into_proxy<'a>(&'a self) -> Result<I::ProxyType, RBoxError>
where P: AsPtr, I: InterfaceType<Serialize = Implemented<Serialize>> + GetSerializeProxyType<'a>,

It serializes a DynTrait<_> into a string by using <ConcreteType as SerializeType>::serialize_impl.

source

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.

source§

impl<'lt, I, EV: Clone> DynTrait<'lt, RArc<()>, I, EV>

source

pub fn shallow_clone(&self) -> Self

Does a shallow clone of the object, just incrementing the reference counter

source§

impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: IteratorItemOrDefault<'borr, Item = Item> + InterfaceType<Iterator = Implemented<Iterator>>, Item: 'borr,

source

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_ptr(&mut iter).interface(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);

source

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_value(0..).interface(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));
source§

impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV>
where Self: Iterator<Item = Item>, P: AsMutPtr, I: IteratorItemOrDefault<'borr, Item = Item> + InterfaceType<DoubleEndedIterator = Implemented<DoubleEndedIterator>>, Item: 'borr,

source

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_value(7..=10).interface(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);
source

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_value(0..=3).interface(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§

source§

impl<'borr, P, I, EV> BufRead for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: InterfaceType<IoRead = Implemented<IoRead>, IoBufRead = Implemented<IoBufRead>>,

source§

fn fill_buf(&mut self) -> Result<&[u8]>

Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
source§

fn consume(&mut self, amount: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to read. Read more
source§

fn has_data_left(&mut self) -> Result<bool, Error>

🔬This is a nightly-only experimental API. (buf_read_has_data_left)
Check if the underlying Read has any data left to be read. Read more
1.0.0 · source§

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes into buf until the delimiter byte or EOF is reached. Read more
source§

fn skip_until(&mut self, byte: u8) -> Result<usize, Error>

🔬This is a nightly-only experimental API. (bufread_skip_until)
Skip all bytes until the delimiter byte or EOF is reached. Read more
1.0.0 · source§

fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided String buffer. Read more
1.0.0 · source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

Returns an iterator over the contents of this reader split on the byte byte. Read more
1.0.0 · source§

fn lines(self) -> Lines<Self>
where Self: Sized,

Returns an iterator over the lines of this reader. Read more
source§

impl<'borr, P, I, EV> Clone for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType, Self: CloneImpl<<P as GetPointerKind>::Kind>,

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

DynTrait does not implement Clone if P ==RMut<'_, ()> :


let mut object = DynTrait::from_value(()).interface(());
let borrow = object.reborrow_mut();
let _ = borrow.clone();
source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'borr, P, I, EV> Debug for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType<Debug = Implemented<Debug>>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, 'borr: 'de, P, I, EV> Deserialize<'de> for DynTrait<'borr, P, I, EV>
where EV: 'borr, P: AsPtr + 'borr, I: InterfaceType + 'borr + DeserializeDyn<'de, Self>, <I as DeserializeDyn<'de, Self>>::Proxy: Deserialize<'de>,

For an example of how to deserialize DynTrait, look here

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'borr, P, I, EV> Display for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType<Display = Implemented<Display>>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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> + InterfaceType<DoubleEndedIterator = Implemented<DoubleEndedIterator>>, Item: 'borr,

source§

fn next_back(&mut self) -> Option<Item>

Removes and returns an element from the end of the iterator. Read more
source§

fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>

🔬This is a nightly-only experimental API. (iter_advance_by)
Advances the iterator from the back by n elements. Read more
1.37.0 · source§

fn nth_back(&mut self, n: usize) -> Option<Self::Item>

Returns the nth element from the end of the iterator. Read more
1.27.0 · source§

fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,

This is the reverse version of Iterator::try_fold(): it takes elements starting from the back of the iterator. Read more
1.27.0 · source§

fn rfold<B, F>(self, init: B, f: F) -> B
where Self: Sized, F: FnMut(B, Self::Item) -> B,

An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. Read more
1.27.0 · source§

fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Searches for an element of an iterator from the back that satisfies a predicate. Read more
source§

impl<'borr, P, I, EV> Drop for DynTrait<'borr, P, I, EV>
where P: GetPointerKind,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'borr, P, I, EV> Error for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl<'borr, P, I, EV> GetStaticEquivalent_ for DynTrait<'borr, P, I, EV>

§

type StaticEquivalent = _static_DynTrait<'static, <P as GetStaticEquivalent_>::StaticEquivalent, <I as GetStaticEquivalent_>::StaticEquivalent, <EV as GetStaticEquivalent_>::StaticEquivalent>

The 'static equivalent of Self
source§

impl<'borr, P, I, EV> Hash for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType<Hash = Implemented<Hash>>,

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: IteratorItemOrDefault<'borr, Item = Item> + InterfaceType<Iterator = Implemented<Iterator>>, Item: 'borr,

§

type Item = Item

The type of the elements being iterated over.
source§

fn next(&mut self) -> Option<Item>

Advances the iterator and returns the next value. Read more
source§

fn nth(&mut self, nth: usize) -> Option<Item>

Returns the nth element of the iterator. Read more
source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the iterator. Read more
source§

fn count(self) -> usize

Consumes the iterator, counting the number of iterations and returning it. Read more
source§

fn last(self) -> Option<Item>

Consumes the iterator, returning the last element. Read more
source§

fn next_chunk<const N: usize>( &mut self ) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
where Self: Sized,

🔬This is a nightly-only experimental API. (iter_next_chunk)
Advances the iterator and returns an array containing the next N values. Read more
source§

fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>

🔬This is a nightly-only experimental API. (iter_advance_by)
Advances the iterator by n elements. Read more
1.28.0 · source§

fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized,

Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
1.0.0 · source§

fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
where Self: Sized, U: IntoIterator<Item = Self::Item>,

Takes two iterators and creates a new iterator over both in sequence. Read more
1.0.0 · source§

fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>
where Self: Sized, U: IntoIterator,

‘Zips up’ two iterators into a single iterator of pairs. Read more
source§

fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
where Self: Sized, G: FnMut() -> Self::Item,

🔬This is a nightly-only experimental API. (iter_intersperse)
Creates a new iterator which places an item generated by separator between adjacent items of the original iterator. Read more
1.0.0 · source§

fn map<B, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> B,

Takes a closure and creates an iterator which calls that closure on each element. Read more
1.21.0 · source§

fn for_each<F>(self, f: F)
where Self: Sized, F: FnMut(Self::Item),

Calls a closure on each element of an iterator. Read more
1.0.0 · source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator which uses a closure to determine if an element should be yielded. Read more
1.0.0 · source§

fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<B>,

Creates an iterator that both filters and maps. Read more
1.0.0 · source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates an iterator which gives the current iteration count as well as the next value. Read more
1.0.0 · source§

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Creates an iterator which can use the peek and peek_mut methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more
1.0.0 · source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator that skips elements based on a predicate. Read more
1.0.0 · source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator that yields elements based on a predicate. Read more
1.57.0 · source§

fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
where Self: Sized, P: FnMut(Self::Item) -> Option<B>,

Creates an iterator that both yields elements based on a predicate and maps. Read more
1.0.0 · source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Creates an iterator that skips the first n elements. Read more
1.0.0 · source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner. Read more
1.0.0 · source§

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>,

An iterator adapter which, like fold, holds internal state, but unlike fold, produces a new iterator. Read more
1.0.0 · source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,

Creates an iterator that works like map, but flattens nested structure. Read more
source§

fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N>
where Self: Sized, F: FnMut(&[Self::Item; N]) -> R,

🔬This is a nightly-only experimental API. (iter_map_windows)
Calls the given function f for each contiguous window of size N over self and returns an iterator over the outputs of f. Like slice::windows(), the windows during mapping overlap as well. Read more
1.0.0 · source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Creates an iterator which ends after the first None. Read more
1.0.0 · source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Does something with each element of an iterator, passing the value on. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Borrows an iterator, rather than consuming it. Read more
1.0.0 · source§

fn collect<B>(self) -> B
where B: FromIterator<Self::Item>, Self: Sized,

Transforms an iterator into a collection. Read more
source§

fn collect_into<E>(self, collection: &mut E) -> &mut E
where E: Extend<Self::Item>, Self: Sized,

🔬This is a nightly-only experimental API. (iter_collect_into)
Collects all the items from an iterator into a collection. Read more
1.0.0 · source§

fn partition<B, F>(self, f: F) -> (B, B)
where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool,

Consumes an iterator, creating two collections from it. Read more
source§

fn is_partitioned<P>(self, predicate: P) -> bool
where Self: Sized, P: FnMut(Self::Item) -> bool,

🔬This is a nightly-only experimental API. (iter_is_partitioned)
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return true precede all those that return false. Read more
1.27.0 · source§

fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,

An iterator method that applies a function as long as it returns successfully, producing a single, final value. Read more
1.27.0 · source§

fn try_for_each<F, R>(&mut self, f: F) -> R
where Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Output = ()>,

An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. Read more
1.0.0 · source§

fn fold<B, F>(self, init: B, f: F) -> B
where Self: Sized, F: FnMut(B, Self::Item) -> B,

Folds every element into an accumulator by applying an operation, returning the final result. Read more
1.51.0 · source§

fn reduce<F>(self, f: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
source§

fn try_reduce<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> R, R: Try<Output = Self::Item>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬This is a nightly-only experimental API. (iterator_try_reduce)
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. Read more
1.0.0 · source§

fn all<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if every element of the iterator matches a predicate. Read more
1.0.0 · source§

fn any<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if any element of the iterator matches a predicate. Read more
1.0.0 · source§

fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Searches for an element of an iterator that satisfies a predicate. Read more
1.30.0 · source§

fn find_map<B, F>(&mut self, f: F) -> Option<B>
where Self: Sized, F: FnMut(Self::Item) -> Option<B>,

Applies function to the elements of iterator and returns the first non-none result. Read more
source§

fn try_find<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType
where Self: Sized, F: FnMut(&Self::Item) -> R, R: Try<Output = bool>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬This is a nightly-only experimental API. (try_find)
Applies function to the elements of iterator and returns the first true result or the first error. Read more
1.0.0 · source§

fn position<P>(&mut self, predicate: P) -> Option<usize>
where Self: Sized, P: FnMut(Self::Item) -> bool,

Searches for an element in an iterator, returning its index. Read more
1.6.0 · source§

fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

Returns the element that gives the maximum value from the specified function. Read more
1.15.0 · source§

fn max_by<F>(self, compare: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the maximum value with respect to the specified comparison function. Read more
1.6.0 · source§

fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

Returns the element that gives the minimum value from the specified function. Read more
1.15.0 · source§

fn min_by<F>(self, compare: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the minimum value with respect to the specified comparison function. Read more
1.0.0 · source§

fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item = (A, B)>,

Converts an iterator of pairs into a pair of containers. Read more
1.36.0 · source§

fn copied<'a, T>(self) -> Copied<Self>
where T: 'a + Copy, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which copies all of its elements. Read more
1.0.0 · source§

fn cloned<'a, T>(self) -> Cloned<Self>
where T: 'a + Clone, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which clones all of its elements. Read more
source§

fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
where Self: Sized,

🔬This is a nightly-only experimental API. (iter_array_chunks)
Returns an iterator over N elements of the iterator at a time. Read more
1.11.0 · source§

fn sum<S>(self) -> S
where Self: Sized, S: Sum<Self::Item>,

Sums the elements of an iterator. Read more
1.11.0 · source§

fn product<P>(self) -> P
where Self: Sized, P: Product<Self::Item>,

Iterates over the entire iterator, multiplying all the elements Read more
source§

fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,

🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
1.5.0 · source§

fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Lexicographically compares the PartialOrd elements of this Iterator with those of another. The comparison works like short-circuit evaluation, returning a result without comparing the remaining elements. As soon as an order can be determined, the evaluation stops and a result is returned. Read more
source§

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>,

🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
1.5.0 · source§

fn eq<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are equal to those of another. Read more
source§

fn eq_by<I, F>(self, other: I, eq: F) -> bool
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,

🔬This is a nightly-only experimental API. (iter_order_by)
Determines if the elements of this Iterator are equal to those of another with respect to the specified equality function. Read more
1.5.0 · source§

fn ne<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are not equal to those of another. Read more
1.5.0 · source§

fn lt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less than those of another. Read more
1.5.0 · source§

fn le<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less or equal to those of another. Read more
1.5.0 · source§

fn gt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than those of another. Read more
1.5.0 · source§

fn ge<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than or equal to those of another. Read more
source§

fn is_sorted_by<F>(self, compare: F) -> bool
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,

🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given comparator function. Read more
source§

fn is_sorted_by_key<F, K>(self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> K, K: PartialOrd,

🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given key extraction function. Read more
source§

impl<P, I, EV> Ord for DynTrait<'static, P, I, EV>
where P: AsPtr, I: InterfaceType<Ord = Implemented<Ord>>, Self: PartialOrd + Eq,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<P, P2, I, EV, EV2> PartialEq<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>
where P: AsPtr, P2: AsPtr, I: InterfaceType<PartialEq = Implemented<PartialEq>>,

source§

fn eq(&self, other: &DynTrait<'static, P2, I, EV2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<P, P2, I, EV, EV2> PartialOrd<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV>
where P: AsPtr, P2: AsPtr, I: InterfaceType<PartialOrd = Implemented<PartialOrd>>, Self: PartialEq<DynTrait<'static, P2, I, EV2>>,

source§

fn partial_cmp(&self, other: &DynTrait<'static, P2, I, EV2>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: InterfaceType<IoRead = Implemented<IoRead>>,

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>

Read the exact number of bytes required to fill buf. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl<'borr, P, I, EV> Seek for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: InterfaceType<IoSeek = Implemented<IoSeek>>,

source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

🔬This is a nightly-only experimental API. (seek_seek_relative)
Seeks relative to the current position. Read more
source§

impl<'borr, P, I, EV> Serialize for DynTrait<'borr, P, I, EV>
where P: AsPtr, I: InterfaceType<Serialize = Implemented<Serialize>> + GetSerializeProxyType<'borr>, I::ProxyType: Serialize,

For an example of how to serialize DynTrait, look here

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'borr, P, I, EV> StableAbi for DynTrait<'borr, P, I, EV>

§

type IsNonZeroType = False

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

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
source§

const ABI_CONSTS: AbiConsts = _

const-equivalents of the associated types.
source§

impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: InterfaceType<IoWrite = Implemented<IoWrite>>,

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this writer. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV>
where P: AsMutPtr, I: InterfaceType<FmtWrite = Implemented<FmtWrite>>,

source§

fn write_str(&mut self, s: &str) -> Result<(), Error>

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
source§

impl<P, I, EV> Eq for DynTrait<'static, P, I, EV>
where Self: PartialEq, P: AsPtr, I: InterfaceType<Eq = Implemented<Eq>>,

source§

impl<'borr, P, I, EV> Send for DynTrait<'borr, P, I, EV>

source§

impl<'borr, P, I, EV> Sync for DynTrait<'borr, P, I, EV>

source§

impl<'borr, P, I, EV> Unpin for DynTrait<'borr, P, I, EV>

Auto Trait Implementations§

§

impl<'borr, P, I, EV> RefUnwindSafe for DynTrait<'borr, P, I, EV>

§

impl<'borr, P, I, EV> UnwindSafe for DynTrait<'borr, P, I, EV>
where EV: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

source§

impl<T> AlignerFor<1> for T

§

type Aligner = AlignTo1<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<1024> for T

§

type Aligner = AlignTo1024<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<128> for T

§

type Aligner = AlignTo128<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<16> for T

§

type Aligner = AlignTo16<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<16384> for T

§

type Aligner = AlignTo16384<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<2> for T

§

type Aligner = AlignTo2<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<2048> for T

§

type Aligner = AlignTo2048<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<256> for T

§

type Aligner = AlignTo256<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<32> for T

§

type Aligner = AlignTo32<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<32768> for T

§

type Aligner = AlignTo32768<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<4> for T

§

type Aligner = AlignTo4<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<4096> for T

§

type Aligner = AlignTo4096<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<512> for T

§

type Aligner = AlignTo512<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<64> for T

§

type Aligner = AlignTo64<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<8> for T

§

type Aligner = AlignTo8<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<8192> for T

§

type Aligner = AlignTo8192<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<I> IntoIterator for I
where I: Iterator,

§

type Item = <I as Iterator>::Item

The type of the elements being iterated over.
§

type IntoIter = I

Which kind of iterator are we turning this into?
const: unstable · source§

fn into_iter(self) -> I

Creates an iterator from a value. Read more
source§

impl<I> IteratorExt for I
where I: Iterator + ?Sized,

source§

fn extending<C>(self, extend: &mut C)
where Self: Sized, C: Extend<Self::Item>,

Collects into an existing collection by extending it. Read more
source§

fn collect_into<C>(self, extend: C) -> C
where Self: Sized, C: Extend<Self::Item>,

Collects into a pre-allocated collection,returning it by value. Read more
source§

fn replace_nth(self, nth: usize, with: Self::Item) -> ReplaceNth<Self>
where Self: Sized,

An Iterator that replaces the nth element with another value. Read more
source§

fn sum_same(self) -> Self::Item
where Self: Sized, Self::Item: Sum,

Sums the items of the iterator, into the item’s type. Read more
source§

fn product_same(self) -> Self::Item
where Self: Sized, Self::Item: Product,

Multiplies the items of the iterator, into the item’s type. Read more
source§

impl<'a, T> RCowCompatibleRef<'a> for T
where T: Clone + 'a,

§

type RefC = &'a T

The (preferably) ffi-safe equivalent of &Self.
§

type ROwned = T

The owned version of Self::RefC.
source§

fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC

Converts a reference to an FFI-safe type
source§

fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T

Converts an FFI-safe type to a reference
source§

impl<S> ROExtAcc for S

source§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

Gets a reference to a field, determined by offset. Read more
source§

fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F

Gets a muatble reference to a field, determined by offset. Read more
source§

fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F

Gets a const pointer to a field, the field is determined by offset. Read more
source§

fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F

Gets a mutable pointer to a field, determined by offset. Read more
source§

impl<S> ROExtOps<Aligned> for S

source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
source§

impl<S> ROExtOps<Unaligned> for S

source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
source§

impl<T> SelfOps for T
where T: ?Sized,

source§

fn eq_id(&self, other: &Self) -> bool

Compares the address of self with the address of other. Read more
source§

fn piped<F, U>(self, f: F) -> U
where F: FnOnce(Self) -> U, Self: Sized,

Emulates the pipeline operator, allowing method syntax in more places. Read more
source§

fn piped_ref<'a, F, U>(&'a self, f: F) -> U
where F: FnOnce(&'a Self) -> U,

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more
source§

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U
where F: FnOnce(&'a mut Self) -> U,

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self.
source§

fn mutated<F>(self, f: F) -> Self
where F: FnOnce(&mut Self), Self: Sized,

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
source§

fn observe<F>(self, f: F) -> Self
where F: FnOnce(&Self), Self: Sized,

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
source§

fn into_<T>(self) -> T
where Self: Into<T>,

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more
source§

fn as_ref_<T>(&self) -> &T
where Self: AsRef<T>, T: ?Sized,

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more
source§

fn as_mut_<T>(&mut self) -> &mut T
where Self: AsMut<T>, T: ?Sized,

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more
source§

fn drop_(self)
where Self: Sized,

Drops self using method notation. Alternative to std::mem::drop. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<This> TransmuteElement for This
where This: ?Sized,

source§

unsafe fn transmute_element<T>( self ) -> <Self as CanTransmuteElement<T>>::TransmutedPtr
where Self: CanTransmuteElement<T>,

Transmutes the element type of this pointer.. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> TypeIdentity for T
where T: ?Sized,

§

type Type = T

This is always Self.
source§

fn into_type(self) -> Self::Type
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
source§

fn as_type(&self) -> &Self::Type

Converts a reference back to the original type.
source§

fn as_type_mut(&mut self) -> &mut Self::Type

Converts a mutable reference back to the original type.
source§

fn into_type_box(self: Box<Self>) -> Box<Self::Type>

Converts a box back to the original type.
source§

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>

Converts an Arc back to the original type. Read more
source§

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>

Converts an Rc back to the original type. Read more
source§

fn from_type(this: Self::Type) -> Self
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
source§

fn from_type_ref(this: &Self::Type) -> &Self

Converts a reference back to the original type.
source§

fn from_type_mut(this: &mut Self::Type) -> &mut Self

Converts a mutable reference back to the original type.
source§

fn from_type_box(this: Box<Self::Type>) -> Box<Self>

Converts a box back to the original type.
source§

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>

Converts an Arc back to the original type.
source§

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>

Converts an Rc back to the original type.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<This> ValidTag_Bounds for This
where This: Debug + Clone + PartialEq,