[−][src]Struct abi_stable::erased_types::dyn_trait::DynTrait
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
implementsstd::ops::Deref
. -
Interface
is anInterfaceType
,which describes what traits are required when constructing theDynTrait<_>
and which ones it implements.
trait InterfaceType
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 unerase the DynTrait afterwards.
-
from_borrowing_ptr Can be constructed from a pointer of a value.Cannot unerase 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 bellow.
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:
-
sabi_into_unerased: Unwraps into a pointer to
T
. WhereDynTrait<P<()>,Interface>
's Interface must equal<T as ImplType>::Interface
-
sabi_as_unerased: Unwraps into a
&T
. WhereDynTrait<P<()>,Interface>
's Interface must equal<T as ImplType>::Interface
-
sabi_as_unerased_mut: Unwraps into a
&mut T
. WhereDynTrait<P<()>,Interface>
's Interface must equal<T as ImplType>::Interface
-
sabi_into_any_unerased:Unwraps into a pointer to
T
.RequiresT:'static
. -
sabi_as_any_unerased:Unwraps into a
&T
.RequiresT:'static
. -
sabi_as_any_unerased_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::{ StableAbi, impl_get_type_info, sabi_extern_fn, erased_types::{ InterfaceType,DeserializeDyn,SerializeProxyType,ImplType,SerializeImplType, TypeInfo, }, external_types::{RawValueRef,RawValueBox}, impl_InterfaceType, prefix_type::PrefixTypeTrait, type_level::bools::*, DynTrait, std_types::{RBox, RStr,RBoxError,RResult,ROk,RErr}, traits::IntoReprC, }; use serde::{Deserialize,Serialize}; /// An `InterfaceType` describing which traits are implemented by FooInterfaceBox. #[repr(C)] #[derive(StableAbi)] pub struct FooInterface; /// The state passed to most functions in the TextOpsMod module. pub type FooInterfaceBox = DynTrait<'static,RBox<()>,FooInterface>; impl_InterfaceType!{ impl InterfaceType for FooInterface { type Send=False; type Debug = True; type Clone = True; type Serialize = True; type Deserialize = True; type PartialEq = True; } } /// First <ConcreteType as DeserializeImplType>::serialize_impl returns /// a RawValueBox containing the serialized data, /// then the returned RawValueBox is serialized. impl SerializeProxyType 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> { get_module() .deserialize_foo()(s.get_rstr()) .into_result() } } #[repr(C)] #[derive(StableAbi)] #[sabi(kind(Prefix(prefix_struct="Module")))] #[sabi(missing_field(panic))] pub struct ModuleVal{ #[sabi(last_prefix_field)] pub deserialize_foo:extern "C" fn(s:RStr<'_>)->RResult<FooInterfaceBox,RBoxError>, } ///////////////////////////////////////////////////////////////////////////////////////// //// 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 SerializeImplType for Foo { type Interface = FooInterface; fn serialize_impl<'a>(&'a 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)), } } 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::{ DynTrait, erased_types::interfaces::PartialEqInterface, std_types::RArc, }; { let left:DynTrait<'static,&(),PartialEqInterface>= DynTrait::from_any_ptr(&100,PartialEqInterface); let mut n100=100; let right:DynTrait<'static,&mut (),PartialEqInterface>= DynTrait::from_any_ptr(&mut n100,PartialEqInterface); assert_eq!(left,right); } { let left= DynTrait::from_any_value(200,PartialEqInterface); let right= 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::{ DynTrait, erased_types::interfaces::FmtWriteInterface, }; use std::fmt::Write; let mut buffer=String::new(); let mut wrapped:DynTrait<'static,&mut (),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::{ DynTrait, erased_types::interfaces::DEIteratorInterface, }; 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,Deref,TransmuteElement}
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 &
or a &mut
,
in which case it should implement GetPointerKind<Kind=PK_Reference>
or GetPointerKind<Kind=PK_MutReference>
respectively.
Example
This is an example of a newtype wrapping an RBox<T>
.
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"], ) } ///////////////////////////////////////// use std::ops::{Deref, DerefMut}; use abi_stable::{ StableAbi, InterfaceType, impl_InterfaceType, std_types::RBox, erased_types::IteratorItem, pointer_trait::{ PK_SmartPointer,GetPointerKind,TransmuteElement }, type_level::bools::True, }; #[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) } } } impl<T> Deref for NewtypeBox<T>{ type Target=T; fn deref(&self)->&T{ &*self.box_ } } impl<T> DerefMut for NewtypeBox<T>{ fn deref_mut(&mut self)->&mut T{ &mut *self.box_ } } unsafe impl<T> GetPointerKind for NewtypeBox<T>{ type Kind=PK_SmartPointer; } unsafe impl<T,O> TransmuteElement<O> for NewtypeBox<T> where // Using this to ensure that the pointer is safe to wrap, // while this is not necessary for `RBox<T>`, // it might be for some other pointer type. RBox<T>:TransmuteElement<O,Kind=Self::Kind> { type TransmutedPtr = NewtypeBox<O>; } ///////////////////////////////////////// #[repr(C)] #[derive(StableAbi)] pub struct IteratorInterface; impl_InterfaceType!{ impl InterfaceType for IteratorInterface { type Iterator = True; type DoubleEndedIterator = True; type Clone = True; type Debug = True; } } impl<'a> IteratorItem<'a> for IteratorInterface{ type Item=&'a str; }
Methods
impl DynTrait<'static, &'static (), ()>
[src]
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_value<T>(object: T) -> DynTrait<'static, RBox<()>, T::Interface> where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, RBox<()>, RBox<T>, <T as ImplType>::Interface>,
[src]
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, RBox<()>, RBox<T>, <T as ImplType>::Interface>,
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<_>
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_ptr<P, T>(
object: P
) -> DynTrait<'static, P::TransmutedPtr, T::Interface> where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, P::TransmutedPtr, P, <T as ImplType>::Interface>,
P: Deref<Target = T> + TransmuteElement<()>,
[src]
object: P
) -> DynTrait<'static, P::TransmutedPtr, T::Interface> where
T: ImplType,
T::Interface: InterfaceBound,
T: GetVtable<'static, T, P::TransmutedPtr, P, <T as ImplType>::Interface>,
P: Deref<Target = T> + TransmuteElement<()>,
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<_>
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_any_value<T, I>(
object: T,
interface: I
) -> DynTrait<'static, RBox<()>, I> where
T: 'static,
I: InterfaceBound,
InterfaceFor<T, I, TU_Unerasable>: GetVtable<'static, T, RBox<()>, RBox<T>, I>,
[src]
object: T,
interface: I
) -> DynTrait<'static, RBox<()>, I> where
T: 'static,
I: InterfaceBound,
InterfaceFor<T, I, TU_Unerasable>: GetVtable<'static, T, RBox<()>, RBox<T>, I>,
Constructs the DynTrait<_>
from a type that doesn't borrow anything.
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_any_ptr<P, T, I>(
object: P,
_interface: I
) -> DynTrait<'static, P::TransmutedPtr, I> where
I: InterfaceBound,
T: 'static,
InterfaceFor<T, I, TU_Unerasable>: GetVtable<'static, T, P::TransmutedPtr, P, I>,
P: Deref<Target = T> + TransmuteElement<()>,
[src]
object: P,
_interface: I
) -> DynTrait<'static, P::TransmutedPtr, I> where
I: InterfaceBound,
T: 'static,
InterfaceFor<T, I, TU_Unerasable>: GetVtable<'static, T, P::TransmutedPtr, P, I>,
P: Deref<Target = T> + TransmuteElement<()>,
Constructs the DynTrait<_>
from a pointer to a
type that doesn't borrow anything.
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_borrowing_value<'borr, T, I>(
object: T,
interface: I
) -> DynTrait<'borr, RBox<()>, I> where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TU_Opaque>: GetVtable<'borr, T, RBox<()>, RBox<T>, I>,
[src]
object: T,
interface: I
) -> DynTrait<'borr, RBox<()>, I> where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TU_Opaque>: GetVtable<'borr, T, RBox<()>, RBox<T>, I>,
Constructs the DynTrait<_>
from a value with a 'borr
borrow.
Cannot unerase the DynTrait afterwards.
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn from_borrowing_ptr<'borr, P, T, I>(
object: P,
_interface: I
) -> DynTrait<'borr, P::TransmutedPtr, I> where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TU_Opaque>: GetVtable<'borr, T, P::TransmutedPtr, P, I>,
P: Deref<Target = T> + TransmuteElement<()>,
[src]
object: P,
_interface: I
) -> DynTrait<'borr, P::TransmutedPtr, I> where
T: 'borr,
I: InterfaceBound,
InterfaceFor<T, I, TU_Opaque>: GetVtable<'borr, T, P::TransmutedPtr, P, I>,
P: Deref<Target = T> + TransmuteElement<()>,
Constructs the DynTrait<_>
from a pointer to the erased type
with a 'borr
borrow.
Cannot unerase the DynTrait afterwards.
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
[src]
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub unsafe fn with_vtable<OrigPtr, Erasability>(
ptr: OrigPtr,
extra_vtable: EV
) -> DynTrait<'borr, P, I, EV> where
OrigPtr::Target: Sized + 'borr,
I: InterfaceBound,
InterfaceFor<OrigPtr::Target, I, Erasability>: GetVtable<'borr, OrigPtr::Target, P, OrigPtr, I>,
OrigPtr: TransmuteElement<(), TransmutedPtr = P> + 'borr,
P: Deref<Target = ()>,
[src]
ptr: OrigPtr,
extra_vtable: EV
) -> DynTrait<'borr, P, I, EV> where
OrigPtr::Target: Sized + 'borr,
I: InterfaceBound,
InterfaceFor<OrigPtr::Target, I, Erasability>: GetVtable<'borr, OrigPtr::Target, P, OrigPtr, I>,
OrigPtr: TransmuteElement<(), TransmutedPtr = P> + 'borr,
P: Deref<Target = ()>,
Constructs an DynTrait from an erased pointer and an extra vtable.
Safety
These are the requirements for the caller:
-
P
must be a pointer to the type thatextra_vtable
functions take as the first parameter. -
The vtable must not come from a reborrowed DynTrait (created using DynTrait::reborrow or DynTrait::reborrow_mut).
-
The vtable must be the
<SomeVTableName>
of a struct declared with#[derive(StableAbi)]``#[sabi(kind(Prefix(prefix_struct="<SomeVTableName>")))]
. -
The vtable must have
StaticRef<RObjectVtable<..>>
as its first declared field
impl<P, I, EV> DynTrait<'static, P, I, EV>
[src]
pub fn sabi_is_same_type<Other, I2, EV2>(
&self,
other: &DynTrait<'static, Other, I2, EV2>
) -> bool where
I2: InterfaceBound,
[src]
&self,
other: &DynTrait<'static, Other, I2, EV2>
) -> bool where
I2: InterfaceBound,
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.
impl<'borr, P, I, EV> DynTrait<'borr, P, I, StaticRef<EV>>
[src]
pub fn sabi_et_vtable<'a>(&self) -> &'a EV
[src]
A vtable used by #[sabi_trait]
derived trait objects.
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
[src]
pub fn sabi_object_address(&self) -> usize where
P: Deref,
[src]
P: Deref,
Returns the address of the wrapped object.
pub fn sabi_erased_ref(&self) -> &ErasedObject where
P: Deref,
[src]
P: Deref,
pub fn sabi_erased_mut(&mut self) -> &mut ErasedObject where
P: DerefMut,
[src]
P: DerefMut,
pub fn sabi_with_value<F, R>(self, f: F) -> R where
P: OwnedPointer<Target = ()>,
F: FnOnce(MovePtr<()>) -> R,
[src]
P: OwnedPointer<Target = ()>,
F: FnOnce(MovePtr<()>) -> R,
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV>
[src]
pub fn sabi_into_unerased<T>(
self
) -> Result<P::TransmutedPtr, UneraseError<Self>> where
P: TransmuteElement<T>,
P::Target: Sized,
T: ImplType,
[src]
self
) -> Result<P::TransmutedPtr, UneraseError<Self>> where
P: TransmuteElement<T>,
P::Target: Sized,
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.
pub fn sabi_as_unerased<T>(&self) -> Result<&T, UneraseError<&Self>> where
P: Deref + TransmuteElement<T>,
T: ImplType,
[src]
P: Deref + TransmuteElement<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.
pub fn sabi_as_unerased_mut<T>(
&mut self
) -> Result<&mut T, UneraseError<&mut Self>> where
P: DerefMut + TransmuteElement<T>,
T: ImplType,
[src]
&mut self
) -> Result<&mut T, UneraseError<&mut Self>> where
P: DerefMut + TransmuteElement<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.
pub fn sabi_into_any_unerased<T>(
self
) -> Result<P::TransmutedPtr, UneraseError<Self>> where
T: 'static,
P: TransmuteElement<T>,
P::Target: Sized,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: ImplType,
[src]
self
) -> Result<P::TransmutedPtr, UneraseError<Self>> where
T: 'static,
P: TransmuteElement<T>,
P::Target: Sized,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: 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.
pub fn sabi_as_any_unerased<T>(&self) -> Result<&T, UneraseError<&Self>> where
T: 'static,
P: Deref + TransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: ImplType,
[src]
T: 'static,
P: Deref + TransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: 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.
pub fn sabi_as_any_unerased_mut<T>(
&mut self
) -> Result<&mut T, UneraseError<&mut Self>> where
P: DerefMut + TransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: ImplType,
[src]
&mut self
) -> Result<&mut T, UneraseError<&mut Self>> where
P: DerefMut + TransmuteElement<T>,
Self: DynTraitBound<'borr>,
InterfaceFor<T, I, TU_Unerasable>: 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.
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV> where
I: InterfaceType,
[src]
I: InterfaceType,
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn reborrow<'re>(&'re self) -> DynTrait<'borr, &'re (), I, EV> where
P: Deref<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
[src]
P: Deref<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
Creates a shared reborrow of this DynTrait.
The reborrowed DynTrait cannot use these methods:
- DynTrait::default
ⓘImportant traits for DynTrait<'borr, P, I, EV>pub fn reborrow_mut<'re>(&'re mut self) -> DynTrait<'borr, &'re mut (), I, EV> where
P: DerefMut<Target = ()>,
PrivStruct: ReborrowBounds<I::Send, I::Sync>,
EV: Copy,
[src]
P: DerefMut<Target = ()>,
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
impl<'borr, P, I, EV> DynTrait<'borr, P, I, EV> where
I: InterfaceBound + 'borr,
EV: 'borr,
[src]
I: InterfaceBound + 'borr,
EV: 'borr,
pub fn default(&self) -> Self where
P: Deref + GetPointerKind<Kind = PK_SmartPointer>,
I: InterfaceType<Default = Implemented<Default>>,
EV: Copy,
[src]
P: Deref + 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();
pub fn serialize_into_proxy(&self) -> Result<I::ProxyType, RBoxError> where
P: Deref,
I: InterfaceType<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType,
[src]
P: Deref,
I: InterfaceType<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType,
It serializes a DynTrait<_>
into a string by using
<ConcreteType as SerializeImplType>::serialize_impl
.
pub fn deserialize_from_proxy<'de>(proxy: I::Proxy) -> Result<Self, RBoxError> where
P: 'borr + Deref,
I: DeserializeDyn<'de, Self>,
[src]
P: 'borr + Deref,
I: DeserializeDyn<'de, Self>,
Deserializes a DynTrait<'borr,_>
from a proxy type,by using
<I as DeserializeDyn<'borr,Self>>::deserialize_dyn
.
impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
[src]
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
pub fn skip_eager(&mut self, n: usize)
[src]
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 );
pub fn extending_rvec(
&mut self,
buffer: &mut RVec<Item>,
taking: ROption<usize>
)
[src]
&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));
impl<'borr, P, I, Item, EV> DynTrait<'borr, P, I, EV> where
Self: Iterator<Item = Item>,
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
[src]
Self: Iterator<Item = Item>,
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
pub fn nth_back_(&mut self, nth: usize) -> Option<Item>
[src]
pub fn extending_rvec_back(
&mut self,
buffer: &mut RVec<Item>,
taking: ROption<usize>
)
[src]
&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
impl<'borr, P, I, EV> GetStaticEquivalent_ for DynTrait<'borr, P, I, EV> where
I: __StableAbi,
EV: __StableAbi,
P: __StableAbi,
I: InterfaceBound,
VTable<'borr, P, I>: SharedStableAbi,
[src]
I: __StableAbi,
EV: __StableAbi,
P: __StableAbi,
I: InterfaceBound,
VTable<'borr, P, I>: SharedStableAbi,
type StaticEquivalent = _static_DynTrait<'static, __GetStaticEquivalent<P>, __GetStaticEquivalent<I>, __GetStaticEquivalent<EV>>
impl<'borr, P, I, EV> SharedStableAbi for DynTrait<'borr, P, I, EV> where
I: __StableAbi,
EV: __StableAbi,
P: __StableAbi,
I: InterfaceBound,
VTable<'borr, P, I>: SharedStableAbi,
[src]
I: __StableAbi,
EV: __StableAbi,
P: __StableAbi,
I: InterfaceBound,
VTable<'borr, P, I>: SharedStableAbi,
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
type Kind = __ValueKind
The kind of abi stability of this type,there are 2: Read more
const S_LAYOUT: &'static TypeLayout
[src]
const S_ABI_INFO: &'static AbiInfoWrapper
[src]
The layout of the type,derived from Self::LAYOUT and associated types.
impl<'borr, P, I, EV> DynTraitBound<'borr> for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound,
[src]
P: Deref,
I: InterfaceBound,
type Interface = I
impl<'borr, P, I, EV> Sync for DynTrait<'borr, P, I, EV> where
P: Sync,
I: InterfaceBound<Sync = Implemented<Sync>>,
[src]
P: Sync,
I: InterfaceBound<Sync = Implemented<Sync>>,
impl<'borr, P, I, Item, EV> DoubleEndedIterator for DynTrait<'borr, P, I, EV> where
Self: Iterator<Item = Item>,
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
[src]
Self: Iterator<Item = Item>,
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<DoubleEndedIterator = Implemented<DoubleEndedIterator>>,
Item: 'borr,
fn next_back(&mut self) -> Option<Item>
[src]
fn nth_back(&mut self, n: usize) -> Option<Self::Item>
1.37.0[src]
Returns the n
th element from the end of the iterator. Read more
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
1.27.0[src]
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
This is the reverse version of [try_fold()
]: it takes elements starting from the back of the iterator. Read more
fn rfold<B, F>(self, accum: B, f: F) -> B where
F: FnMut(B, Self::Item) -> B,
1.27.0[src]
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
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item> where
P: FnMut(&Self::Item) -> bool,
1.27.0[src]
P: FnMut(&Self::Item) -> bool,
Searches for an element of an iterator from the back that satisfies a predicate. Read more
impl<'borr, P, I, EV> Clone for DynTrait<'borr, P, I, EV> where
P: Deref + GetPointerKind,
I: InterfaceBound,
Self: CloneImpl<<P as GetPointerKind>::Kind>,
[src]
P: Deref + GetPointerKind,
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==&mut ()
:
let mut object=DynTrait::from_any_value((),()); let borrow=object.reborrow_mut(); let _=borrow.clone();
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<P, I, EV> Ord for DynTrait<'static, P, I, EV> where
P: Deref,
I: InterfaceBound<Ord = Implemented<Ord>>,
Self: PartialOrd + Eq,
[src]
P: Deref,
I: InterfaceBound<Ord = Implemented<Ord>>,
Self: PartialOrd + Eq,
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<P, P2, I, EV, EV2> PartialOrd<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV> where
P: Deref,
P2: Deref,
I: InterfaceBound<PartialOrd = Implemented<PartialOrd>>,
Self: PartialEq<DynTrait<'static, P2, I, EV2>>,
[src]
P: Deref,
P2: Deref,
I: InterfaceBound<PartialOrd = Implemented<PartialOrd>>,
Self: PartialEq<DynTrait<'static, P2, I, EV2>>,
fn partial_cmp(&self, other: &DynTrait<'static, P2, I, EV2>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<P, P2, I, EV, EV2> PartialEq<DynTrait<'static, P2, I, EV2>> for DynTrait<'static, P, I, EV> where
P: Deref,
P2: Deref,
I: InterfaceBound<PartialEq = Implemented<PartialEq>>,
[src]
P: Deref,
P2: Deref,
I: InterfaceBound<PartialEq = Implemented<PartialEq>>,
fn eq(&self, other: &DynTrait<'static, P2, I, EV2>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'borr, P, I, Item, EV> Iterator for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
[src]
P: DerefMut,
I: IteratorItemOrDefault<'borr, Item = Item>,
I: InterfaceBound<Iterator = Implemented<Iterator>>,
Item: 'borr,
type Item = Item
The type of the elements being iterated over.
fn next(&mut self) -> Option<Item>
[src]
fn nth(&mut self, nth: usize) -> Option<Item>
[src]
fn size_hint(&self) -> (usize, Option<usize>)
[src]
fn count(self) -> usize
[src]
fn last(self) -> Option<Item>
[src]
fn step_by(self, step: usize) -> StepBy<Self>
1.28.0[src]
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator<Item = Self::Item>,
1.0.0[src]
U: IntoIterator<Item = Self::Item>,
Takes two iterators and creates a new iterator over both in sequence. Read more
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator,
1.0.0[src]
U: IntoIterator,
'Zips up' two iterators into a single iterator of pairs. Read more
fn map<B, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> B,
1.0.0[src]
F: FnMut(Self::Item) -> B,
Takes a closure and creates an iterator which calls that closure on each element. Read more
fn for_each<F>(self, f: F) where
F: FnMut(Self::Item),
1.21.0[src]
F: FnMut(Self::Item),
Calls a closure on each element of an iterator. Read more
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
1.0.0[src]
P: FnMut(&Self::Item) -> bool,
Creates an iterator which uses a closure to determine if an element should be yielded. Read more
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<B>,
1.0.0[src]
F: FnMut(Self::Item) -> Option<B>,
Creates an iterator that both filters and maps. Read more
fn enumerate(self) -> Enumerate<Self>
1.0.0[src]
Creates an iterator which gives the current iteration count as well as the next value. Read more
fn peekable(self) -> Peekable<Self>
1.0.0[src]
Creates an iterator which can use peek
to look at the next element of the iterator without consuming it. Read more
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
1.0.0[src]
P: FnMut(&Self::Item) -> bool,
Creates an iterator that [skip
]s elements based on a predicate. Read more
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
1.0.0[src]
P: FnMut(&Self::Item) -> bool,
Creates an iterator that yields elements based on a predicate. Read more
fn skip(self, n: usize) -> Skip<Self>
1.0.0[src]
Creates an iterator that skips the first n
elements. Read more
fn take(self, n: usize) -> Take<Self>
1.0.0[src]
Creates an iterator that yields its first n
elements. Read more
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
F: FnMut(&mut St, Self::Item) -> Option<B>,
1.0.0[src]
F: FnMut(&mut St, Self::Item) -> Option<B>,
An iterator adaptor similar to [fold
] that holds internal state and produces a new iterator. Read more
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
F: FnMut(Self::Item) -> U,
U: IntoIterator,
1.0.0[src]
F: FnMut(Self::Item) -> U,
U: IntoIterator,
Creates an iterator that works like map, but flattens nested structure. Read more
fn flatten(self) -> Flatten<Self> where
Self::Item: IntoIterator,
1.29.0[src]
Self::Item: IntoIterator,
Creates an iterator that flattens nested structure. Read more
fn fuse(self) -> Fuse<Self>
1.0.0[src]
Creates an iterator which ends after the first [None
]. Read more
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
1.0.0[src]
F: FnMut(&Self::Item),
Do something with each element of an iterator, passing the value on. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Borrows an iterator, rather than consuming it. Read more
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
fn collect<B>(self) -> B where
B: FromIterator<Self::Item>,
1.0.0[src]
B: FromIterator<Self::Item>,
Transforms an iterator into a collection. Read more
fn partition<B, F>(self, f: F) -> (B, B) where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
1.0.0[src]
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
Consumes an iterator, creating two collections from it. Read more
fn partition_in_place<'a, T, P>(self, predicate: P) -> usize where
P: FnMut(&T) -> bool,
Self: DoubleEndedIterator<Item = &'a mut T>,
T: 'a,
[src]
P: FnMut(&T) -> bool,
Self: DoubleEndedIterator<Item = &'a mut T>,
T: 'a,
🔬 This is a nightly-only experimental API. (iter_partition_in_place
)
new API
Reorder the elements of this iterator in-place according to the given predicate, such that all those that return true
precede all those that return false
. Returns the number of true
elements found. Read more
fn is_partitioned<P>(self, predicate: P) -> bool where
P: FnMut(Self::Item) -> bool,
[src]
P: FnMut(Self::Item) -> bool,
🔬 This is a nightly-only experimental API. (iter_is_partitioned
)
new API
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
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
1.27.0[src]
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. Read more
fn try_for_each<F, R>(&mut self, f: F) -> R where
F: FnMut(Self::Item) -> R,
R: Try<Ok = ()>,
1.27.0[src]
F: FnMut(Self::Item) -> R,
R: Try<Ok = ()>,
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
fn fold<B, F>(self, init: B, f: F) -> B where
F: FnMut(B, Self::Item) -> B,
1.0.0[src]
F: FnMut(B, Self::Item) -> B,
An iterator method that applies a function, producing a single, final value. Read more
fn all<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
1.0.0[src]
F: FnMut(Self::Item) -> bool,
Tests if every element of the iterator matches a predicate. Read more
fn any<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
1.0.0[src]
F: FnMut(Self::Item) -> bool,
Tests if any element of the iterator matches a predicate. Read more
fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where
P: FnMut(&Self::Item) -> bool,
1.0.0[src]
P: FnMut(&Self::Item) -> bool,
Searches for an element of an iterator that satisfies a predicate. Read more
fn find_map<B, F>(&mut self, f: F) -> Option<B> where
F: FnMut(Self::Item) -> Option<B>,
1.30.0[src]
F: FnMut(Self::Item) -> Option<B>,
Applies function to the elements of iterator and returns the first non-none result. Read more
fn position<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
1.0.0[src]
P: FnMut(Self::Item) -> bool,
Searches for an element in an iterator, returning its index. Read more
fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
Self: ExactSizeIterator + DoubleEndedIterator,
1.0.0[src]
P: FnMut(Self::Item) -> bool,
Self: ExactSizeIterator + DoubleEndedIterator,
Searches for an element in an iterator from the right, returning its index. Read more
fn max(self) -> Option<Self::Item> where
Self::Item: Ord,
1.0.0[src]
Self::Item: Ord,
Returns the maximum element of an iterator. Read more
fn min(self) -> Option<Self::Item> where
Self::Item: Ord,
1.0.0[src]
Self::Item: Ord,
Returns the minimum element of an iterator. Read more
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
1.6.0[src]
B: Ord,
F: FnMut(&Self::Item) -> B,
Returns the element that gives the maximum value from the specified function. Read more
fn max_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.15.0[src]
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Returns the element that gives the maximum value with respect to the specified comparison function. Read more
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
1.6.0[src]
B: Ord,
F: FnMut(&Self::Item) -> B,
Returns the element that gives the minimum value from the specified function. Read more
fn min_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.15.0[src]
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Returns the element that gives the minimum value with respect to the specified comparison function. Read more
fn rev(self) -> Rev<Self> where
Self: DoubleEndedIterator,
1.0.0[src]
Self: DoubleEndedIterator,
Reverses an iterator's direction. Read more
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Iterator<Item = (A, B)>,
1.0.0[src]
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Iterator<Item = (A, B)>,
Converts an iterator of pairs into a pair of containers. Read more
fn copied<'a, T>(self) -> Copied<Self> where
Self: Iterator<Item = &'a T>,
T: 'a + Copy,
1.36.0[src]
Self: Iterator<Item = &'a T>,
T: 'a + Copy,
Creates an iterator which copies all of its elements. Read more
fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Iterator<Item = &'a T>,
T: 'a + Clone,
1.0.0[src]
Self: Iterator<Item = &'a T>,
T: 'a + Clone,
Creates an iterator which [clone
]s all of its elements. Read more
fn cycle(self) -> Cycle<Self> where
Self: Clone,
1.0.0[src]
Self: Clone,
Repeats an iterator endlessly. Read more
fn sum<S>(self) -> S where
S: Sum<Self::Item>,
1.11.0[src]
S: Sum<Self::Item>,
Sums the elements of an iterator. Read more
fn product<P>(self) -> P where
P: Product<Self::Item>,
1.11.0[src]
P: Product<Self::Item>,
Iterates over the entire iterator, multiplying all the elements Read more
fn cmp<I>(self, other: I) -> Ordering where
I: IntoIterator<Item = Self::Item>,
Self::Item: Ord,
1.5.0[src]
I: IntoIterator<Item = Self::Item>,
Self::Item: Ord,
Lexicographically compares the elements of this Iterator
with those of another. Read more
fn partial_cmp<I>(self, other: I) -> Option<Ordering> where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Lexicographically compares the elements of this Iterator
with those of another. Read more
fn eq<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are equal to those of another. Read more
fn ne<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are unequal to those of another. Read more
fn lt<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are lexicographically less than those of another. Read more
fn le<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are lexicographically less or equal to those of another. Read more
fn gt<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are lexicographically greater than those of another. Read more
fn ge<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
1.5.0[src]
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Determines if the elements of this Iterator
are lexicographically greater than or equal to those of another. Read more
fn is_sorted(self) -> bool where
Self::Item: PartialOrd<Self::Item>,
[src]
Self::Item: PartialOrd<Self::Item>,
🔬 This is a nightly-only experimental API. (is_sorted
)
new API
Checks if the elements of this iterator are sorted. Read more
fn is_sorted_by<F>(self, compare: F) -> bool where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
[src]
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
🔬 This is a nightly-only experimental API. (is_sorted
)
new API
Checks if the elements of this iterator are sorted using the given comparator function. Read more
fn is_sorted_by_key<F, K>(self, f: F) -> bool where
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
[src]
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
🔬 This is a nightly-only experimental API. (is_sorted
)
new API
Checks if the elements of this iterator are sorted using the given key extraction function. Read more
impl<'borr, P, I, EV> Drop for DynTrait<'borr, P, I, EV>
[src]
impl<'borr, P, I, EV> Send for DynTrait<'borr, P, I, EV> where
P: Send,
I: InterfaceBound<Send = Implemented<Send>>,
[src]
P: Send,
I: InterfaceBound<Send = Implemented<Send>>,
impl<P, I, EV> Eq for DynTrait<'static, P, I, EV> where
Self: PartialEq,
P: Deref,
I: InterfaceBound<Eq = Implemented<Eq>>,
[src]
Self: PartialEq,
P: Deref,
I: InterfaceBound<Eq = Implemented<Eq>>,
impl<'borr, P, I, EV> Display for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound<Display = Implemented<Display>>,
[src]
P: Deref,
I: InterfaceBound<Display = Implemented<Display>>,
impl<'borr, P, I, EV> Debug for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound<Debug = Implemented<Debug>>,
[src]
P: Deref,
I: InterfaceBound<Debug = Implemented<Debug>>,
impl<'borr, P, I, EV> Hash for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound<Hash = Implemented<Hash>>,
[src]
P: Deref,
I: InterfaceBound<Hash = Implemented<Hash>>,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: InterfaceBound<FmtWrite = Implemented<FmtWrite>>,
[src]
P: DerefMut,
I: InterfaceBound<FmtWrite = Implemented<FmtWrite>>,
fn write_str(&mut self, s: &str) -> Result<(), Error>
[src]
fn write_char(&mut self, c: char) -> Result<(), Error>
1.1.0[src]
Writes a [char
] into this writer, returning whether the write succeeded. Read more
fn write_fmt(&mut self, args: Arguments) -> Result<(), Error>
1.0.0[src]
Glue for usage of the [write!
] macro with implementors of this trait. Read more
impl<'borr, P, I, EV> Error for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,
[src]
P: Deref,
I: InterfaceBound<Display = Implemented<Display>, Debug = Implemented<Debug>, Error = Implemented<Error>>,
fn description(&self) -> &str
1.0.0[src]
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
The lower-level source of this error, if any. Read more
impl<'borr, P, I, EV> Read for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
[src]
P: DerefMut,
I: InterfaceBound<IoRead = Implemented<IoRead>>,
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
Like read
, except that it reads into a slice of buffers. Read more
unsafe fn initializer(&self) -> Initializer
[src]
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, appending them to buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Creates an adaptor which will read at most limit
bytes from it. Read more
impl<'borr, P, I, EV> BufRead for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: InterfaceBound<IoRead = Implemented<IoRead>, IoBufRead = Implemented<IoBufRead>>,
[src]
P: DerefMut,
I: InterfaceBound<IoRead = Implemented<IoRead>, IoBufRead = Implemented<IoBufRead>>,
fn fill_buf(&mut self) -> Result<&[u8]>
[src]
fn consume(&mut self, ammount: usize)
[src]
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more
fn split(self, byte: u8) -> Split<Self>
1.0.0[src]
Returns an iterator over the contents of this reader split on the byte byte
. Read more
fn lines(self) -> Lines<Self>
1.0.0[src]
Returns an iterator over the lines of this reader. Read more
impl<'borr, P, I, EV> Write for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,
[src]
P: DerefMut,
I: InterfaceBound<IoWrite = Implemented<IoWrite>>,
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_all(&mut self, buf: &[u8]) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
Like write
, except that it writes from a slice of buffers. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<'borr, P, I, EV> Seek for DynTrait<'borr, P, I, EV> where
P: DerefMut,
I: InterfaceBound<IoSeek = Implemented<IoSeek>>,
[src]
P: DerefMut,
I: InterfaceBound<IoSeek = Implemented<IoSeek>>,
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
[src]
fn stream_len(&mut self) -> Result<u64, Error>
[src]
seek_convenience
)Returns the length of this stream (in bytes). Read more
fn stream_position(&mut self) -> Result<u64, Error>
[src]
seek_convenience
)Returns the current seek position from the start of the stream. Read more
impl<'de, 'borr: 'de, P, I, EV> Deserialize<'de> for DynTrait<'borr, P, I, EV> where
EV: 'borr,
P: Deref + 'borr,
I: InterfaceBound + 'borr,
I: DeserializeDyn<'de, Self>,
<I as DeserializeDyn<'de, Self>>::Proxy: Deserialize<'de>,
[src]
EV: 'borr,
P: Deref + '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
.
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<'borr, P, I, EV> Serialize for DynTrait<'borr, P, I, EV> where
P: Deref,
I: InterfaceBound<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType,
I::ProxyType: Serialize,
[src]
P: Deref,
I: InterfaceBound<Serialize = Implemented<Serialize>>,
I: GetSerializeProxyType,
I::ProxyType: Serialize,
First it serializes a DynTrait<_>
into a string by using
Auto Trait Implementations
impl<'borr, P, I, EV> Unpin for DynTrait<'borr, P, I, EV> where
EV: Unpin,
P: Unpin,
EV: Unpin,
P: Unpin,
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,
EV: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
impl<This> StableAbi for This where
This: SharedStableAbi<Kind = ValueKind>,
[src]
This: SharedStableAbi<Kind = ValueKind>,
const LAYOUT: &'static TypeLayout
[src]
const ABI_INFO: &'static AbiInfoWrapper
[src]
impl<T> MakeGetAbiInfo<StableAbi_Bound> for T where
T: StableAbi,
[src]
T: StableAbi,
const CONST: GetAbiInfo
[src]
impl<T> MakeGetAbiInfo<SharedStableAbi_Bound> for T where
T: SharedStableAbi,
[src]
T: SharedStableAbi,
const CONST: GetAbiInfo
[src]
impl<T> MakeGetAbiInfo<UnsafeOpaqueField_Bound> for T
[src]
const CONST: GetAbiInfo
[src]
impl<'a, T> BorrowOwned<'a> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
type ROwned = T
type RBorrowed = &'a T
fn r_borrow(
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
fn r_to_owned(
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
[src]
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
fn deref_borrowed(&<T as BorrowOwned<'a>>::RBorrowed) -> &T
[src]
fn deref_owned(&<T as BorrowOwned<'a>>::ROwned) -> &T
[src]
fn from_cow_borrow(&'a T) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
fn from_cow_owned(<T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
[src]
fn into_cow_borrow(<T as BorrowOwned<'a>>::RBorrowed) -> &'a T
[src]
fn into_cow_owned(<T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
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?
fn into_iter(self) -> I
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> TypeIdentity for T where
T: ?Sized,
[src]
T: ?Sized,
type Type = T
The same type as Self. Read more
fn into_type_val(self) -> Self::Type where
Self::Type: Sized,
[src]
Self::Type: Sized,
Converts a value back to the original type.
fn into_type_ref(&self) -> &Self::Type
[src]
Converts a reference back to the original type.
fn into_type_mut(&mut self) -> &mut Self::Type
[src]
Converts a mutable reference back to the original type.
fn into_type_box(self: Box<Self>) -> Box<Self::Type>
[src]
Converts a box back to the original type.
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
[src]
Converts an Arc back to the original type.
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
[src]
Converts an Rc back to the original type.
fn from_type_val(this: Self::Type) -> Self where
Self::Type: Sized,
[src]
Self::Type: Sized,
Converts a value back to the original type.
fn from_type_ref(this: &Self::Type) -> &Self
[src]
Converts a reference back to the original type.
fn from_type_mut(this: &mut Self::Type) -> &mut Self
[src]
Converts a mutable reference back to the original type.
fn from_type_box(this: Box<Self::Type>) -> Box<Self>
[src]
Converts a box back to the original type.
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>
[src]
Converts an Arc back to the original type.
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>
[src]
Converts an Rc back to the original type.
impl<I> IteratorExt for I where
I: Iterator,
[src]
I: Iterator,
fn collect_<T>(self, PhantomData<fn() -> T>) -> T where
T: FromIterator<Self::Item>,
[src]
T: FromIterator<Self::Item>,
Alternative to Iterator::collect . Read more
fn extending<C>(self, extend: &mut C) where
C: Extend<Self::Item>,
[src]
C: Extend<Self::Item>,
Collects into an existing collection by extending it. Read more
fn collect_into<C>(self, extend: C) -> C where
C: Extend<Self::Item>,
[src]
C: Extend<Self::Item>,
Collects into a pre-allocated collection,returning it by value. Read more
fn replace_nth(self, nth: usize, with: Self::Item) -> ReplaceNth<Self>
[src]
An Iterator that replaces the nth element with another value. Read more
impl<T> SelfOps for T where
T: ?Sized,
[src]
T: ?Sized,
const T: PhantomData<fn() -> Self>
[src]
Represents Self by using a VariantPhantom, using the syntax Type::T
to pass it in methods with _:VariantPhantom<T>
parameters. Read more
const T_D: PhantomData<Self>
[src]
Represents Self by using a VariantDropPhantom,for specialized cases. Read more
fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self
[src]
Asserts that other
is the same type as self
.
fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self
[src]
Asserts that other
is the same type as self
.
fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self
[src]
Asserts that other
is the same type as self
.
fn ty_(&self) -> PhantomData<fn() -> Self>
[src]
Equivalent to SelfOps::T,as a method. Read more
fn ty_d(&self) -> PhantomData<Self>
[src]
Equivalent to [Self::ty_],for specialized cases. Read more
fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>
[src]
Equivalent to [Self::ty_] with an invariant type.
fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>
[src]
Equivalent to [Self::ty_] with an invariant lifetime.
fn eq_id(&self, other: &Self) -> bool
[src]
Identity comparison to another value of the same type. Read more
fn piped<F, U>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
Emulates the pipeline operator,allowing method syntax in more places. Read more
fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
F: FnOnce(&'a Self) -> U,
[src]
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
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U where
F: FnOnce(&'a mut Self) -> U,
[src]
F: FnOnce(&'a mut Self) -> U,
The same as piped
except that the function takes &mut Self
. Useful for functions that take &mut Self
instead of Self
. Read more
fn mutated<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
fn observe<F>(self, f: F) -> Self where
F: FnOnce(&Self),
[src]
F: FnOnce(&Self),
Observes the value of self passing it along unmodified. Useful in a long method chain. Read more
fn into_<T>(self, PhantomData<fn() -> T>) -> T where
Self: Into<T>,
[src]
Self: Into<T>,
Performs a conversion using Into. Read more
fn as_ref_<T>(&self) -> &T where
Self: AsRef<T>,
T: ?Sized,
[src]
Self: AsRef<T>,
T: ?Sized,
Performs a reference to reference conversion using AsRef, using the turbofish .as_ref_::<_>()
syntax. Read more
fn as_mut_<T>(&mut self) -> &mut T where
Self: AsMut<T>,
T: ?Sized,
[src]
Self: AsMut<T>,
T: ?Sized,
Performs a mutable reference to mutable reference conversion using AsMut, using the turbofish .as_mut_::<_>()
syntax. Read more
fn drop_(self)
[src]
Drops self
using method notation. Alternative to std::mem::drop
. Read more
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The error type returned when the conversion fails.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<I> IteratorRandom for I where
I: Iterator,
[src]
I: Iterator,
fn choose<R>(self, rng: &mut R) -> Option<Self::Item> where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
Choose one element at random from the iterator. If you have a slice, it's significantly faster to call the [choose
] or [choose_mut
] functions using the slice instead. Read more
fn choose_multiple_fill<R>(self, rng: &mut R, buf: &mut [Self::Item]) -> usize where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
Collects amount
values at random from the iterator into a supplied buffer. Read more
fn choose_multiple<R>(self, rng: &mut R, amount: usize) -> Vec<Self::Item> where
R: Rng + ?Sized,
[src]
R: Rng + ?Sized,
Collects amount
values at random from the iterator into a vector. Read more