Expand description
An pointer for Objective-C reference counted objects.
Id
strongly references or “retains” the given object T
, and
“releases” it again when dropped, thereby ensuring it will be deallocated
at the right time.
An Id
can either be Owned
or Shared
, represented with the O
type parameter.
If owned, it is guaranteed that there are no other references to the
object, and the Id
can therefore be mutably dereferenced.
If shared, however, it can only be immutably dereferenced because there
may be other references to the object, since a shared Id
can be cloned
to provide exactly that.
An Id<T, Owned>
can be safely converted to a Id<T, Shared>
using
Id::into_shared
or From
/Into
. The opposite is not safely possible,
but the unsafe option Id::from_shared
is provided.
Option<Id<T, O>>
is guaranteed to have the same size as a pointer to the
object.
Comparison to std
types
Id<T, Owned>
can be thought of as the Objective-C equivalent of Box
from the standard library: It is a unique pointer to some allocated
object, and that means you’re allowed to get a mutable reference to it.
Likewise, Id<T, Shared>
is the Objective-C equivalent of Arc
: It is
a reference-counting pointer that, when cloned, increases the reference
count.
Caveats
If the inner type implements Drop
, that implementation will not be
called, since there is no way to ensure that the Objective-C runtime will
do so. If you need to run some code when the object is destroyed,
implement the dealloc
method instead.
This allows ?Sized
types T
, but the intention is to only support when
T
is an extern type
(yet unstable).
Examples
use objc2::msg_send_id;
use objc2::runtime::{Class, Object};
use objc2::rc::{Id, Owned, Shared, WeakId};
let cls = Class::get("NSObject").unwrap();
let obj: Id<Object, Owned> = unsafe { msg_send_id![cls, new] };
// obj will be released when it goes out of scope
// share the object so we can clone it
let obj: Id<_, Shared> = obj.into();
let another_ref = obj.clone();
// dropping our other reference will decrement the retain count
drop(another_ref);
let weak = WeakId::new(&obj);
assert!(weak.load().is_some());
// After the object is deallocated, our weak pointer returns none
drop(obj);
assert!(weak.load().is_none());
let mut owned: Id<T, Owned>;
let mut_ref: &mut T = &mut *owned;
// Do something with `&mut T` here
let shared: Id<T, Shared> = owned.into();
let cloned: Id<T, Shared> = shared.clone();
// Do something with `&T` here
Implementations
sourceimpl<T: Message + ?Sized, O: Ownership> Id<T, O>
impl<T: Message + ?Sized, O: Ownership> Id<T, O>
sourcepub unsafe fn new(ptr: *mut T) -> Option<Id<T, O>>
pub unsafe fn new(ptr: *mut T) -> Option<Id<T, O>>
Constructs an Id
to an object that already has +1 retain count.
This is useful when you have a retain count that has been handed off
from somewhere else, usually Objective-C methods like init
, alloc
,
new
, copy
, or methods with the ns_returns_retained
attribute.
Since most of the above methods create new objects, and you therefore
hold unique access to the object, you would often set the ownership to
be Owned
.
But some immutable objects (like NSString
) don’t always return
unique references, so in those case you would use Shared
.
Returns None
if the pointer was null.
Safety
The caller must ensure the given object has +1 retain count, and that
the object pointer otherwise follows the same safety requirements as
in Id::retain
.
Example
let cls: &Class;
let obj: &mut Object = unsafe { msg_send![cls, alloc] };
let obj: Id<Object, Owned> = unsafe { Id::new(msg_send![obj, init]).unwrap() };
// Or utilizing `msg_send_id`:
let obj = unsafe { msg_send_id![cls, alloc] };
let obj: Id<Object, Owned> = unsafe { msg_send_id![obj, init] };
// Or in this case simply just:
let obj: Id<Object, Owned> = unsafe { msg_send_id![cls, new] };
let cls = class!(NSString);
// NSString is immutable, so don't create an owned reference to it
let obj: Id<NSString, Shared> = unsafe { msg_send_id![cls, new] };
sourcepub fn as_ptr(this: &Id<T, O>) -> *const T
pub fn as_ptr(this: &Id<T, O>) -> *const T
Returns a raw pointer to the object.
The pointer is valid for at least as long as the Id
is held.
See Id::as_mut_ptr
for the mutable equivalent.
This is an associated method, and must be called as Id::as_ptr(obj)
.
sourceimpl<T: Message + ?Sized> Id<T, Owned>
impl<T: Message + ?Sized> Id<T, Owned>
sourcepub fn as_mut_ptr(this: &mut Id<T, Owned>) -> *mut T
pub fn as_mut_ptr(this: &mut Id<T, Owned>) -> *mut T
Returns a raw mutable pointer to the object.
The pointer is valid for at least as long as the Id
is held.
See Id::as_ptr
for the immutable equivalent.
This is an associated method, and must be called as
Id::as_mut_ptr(obj)
.
sourceimpl<T: Message, O: Ownership> Id<T, O>
impl<T: Message, O: Ownership> Id<T, O>
sourcepub unsafe fn cast<U: Message>(this: Self) -> Id<U, O>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
pub unsafe fn cast<U: Message>(this: Self) -> Id<U, O>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
Convert the type of the given object to another.
This is equivalent to a cast
between two pointers.
See Id::into_super
for a safe alternative.
This is common to do when you know that an object is a subclass of
a specific class (e.g. casting an instance of NSString
to NSObject
is safe because NSString
is a subclass of NSObject
).
All 'static
objects can safely be cast to Object
, since that
assumes no specific class.
Safety
You must ensure that the object can be reinterpreted as the given type.
If T
is not 'static
, you must ensure that U
ensures that the
data contained by T
is kept alive for as long as U
lives.
Additionally, you must ensure that any safety invariants that the new type has are upheld.
sourcepub unsafe fn retain(ptr: *mut T) -> Option<Id<T, O>>
pub unsafe fn retain(ptr: *mut T) -> Option<Id<T, O>>
Retains the given object pointer.
This is useful when you have been given a pointer to an object from some API, and you would like to ensure that the object stays around so that you can work with it.
If said API is a normal Objective-C method, you probably want to use
Id::retain_autoreleased
instead.
This is rarely used to construct owned Id
s, see Id::new
for
that.
Returns None
if the pointer was null.
Safety
The caller must ensure that the ownership is correct; that is, there
must be no Owned
pointers or mutable references to the same
object, and when creating owned Id
s, there must be no other
pointers or references to the object.
Additionally, the pointer must be valid as a reference (aligned,
dereferencable and initialized, see the std::ptr
module for more
information).
Finally, if you do not know the concrete type of T
, it may not be
'static
, and hence you must ensure that the data that T
references
lives for as long as T
.
sourcepub unsafe fn retain_autoreleased(ptr: *mut T) -> Option<Id<T, O>>
pub unsafe fn retain_autoreleased(ptr: *mut T) -> Option<Id<T, O>>
Retains a previously autoreleased object pointer.
This is useful when calling Objective-C methods that return autoreleased objects, see Cocoa’s Memory Management Policy.
This has exactly the same semantics as Id::retain
, except it can
sometimes avoid putting the object into the autorelease pool, possibly
yielding increased speed and reducing memory pressure.
Note: This relies heavily on being inlined right after msg_send!
,
be careful not accidentally require instructions between these.
Safety
Same as Id::retain
.
sourcepub fn autorelease_return(self) -> *mut T
pub fn autorelease_return(self) -> *mut T
Autoreleases and prepares the Id
to be returned to Objective-C.
The object is not immediately released, but will be when the innermost autorelease pool is drained.
This is useful when declaring your own methods where you will often find yourself in need of returning autoreleased objects to properly follow Cocoa’s Memory Management Policy.
To that end, you could use Id::autorelease
, but that would require
you to have an AutoreleasePool
object at hand, which you clearly
won’t have in such cases. This function doesn’t require a pool
object (but as a downside returns a pointer instead of a reference).
This is also more efficient than a normal autorelease
, it makes a
best effort attempt to hand off ownership of the retain count to a
subsequent call to objc_retainAutoreleasedReturnValue
/
Id::retain_autoreleased
in the enclosing call frame. Note: This
optimization relies heavily on this function being tail called, so be
careful to call this function at the end of your method.
Examples
use objc2::{class, msg_send_id, sel};
use objc2::declare::ClassBuilder;
use objc2::rc::{Id, Owned};
use objc2::runtime::{Class, Object, Sel};
let mut builder = ClassBuilder::new("ExampleObject", class!(NSObject)).unwrap();
extern "C" fn get(cls: &Class, _cmd: Sel) -> *mut Object {
let obj: Id<Object, Owned> = unsafe { msg_send_id![cls, new] };
obj.autorelease_return()
}
unsafe {
builder.add_class_method(
sel!(get),
get as extern "C" fn(_, _) -> _,
);
}
let cls = builder.register();
sourceimpl<T: Message> Id<T, Owned>
impl<T: Message> Id<T, Owned>
sourcepub fn autorelease<'p>(self, pool: &'p AutoreleasePool) -> &'p mut T
pub fn autorelease<'p>(self, pool: &'p AutoreleasePool) -> &'p mut T
Autoreleases the owned Id
, returning a mutable reference bound to
the pool.
The object is not immediately released, but will be when the innermost / current autorelease pool (given as a parameter) is drained.
Promote a shared Id
to an owned one, allowing it to be mutated.
Safety
The caller must ensure that there are no other pointers (including
WeakId
pointers) to the same object.
This also means that the given Id
should have a retain count of
exactly 1 (except when autoreleases are involved).
In general, this is wildly unsafe, do see if you can find a different solution!
Convert an owned to a shared Id
, allowing it to be cloned.
This is also implemented as a From
conversion, but this name is more
explicit, which may be useful in some cases.
sourcepub fn autorelease<'p>(self, pool: &'p AutoreleasePool) -> &'p T
pub fn autorelease<'p>(self, pool: &'p AutoreleasePool) -> &'p T
Autoreleases the shared Id
, returning an aliased reference bound
to the pool.
The object is not immediately released, but will be when the innermost / current autorelease pool (given as a parameter) is drained.
sourceimpl<T: ClassType + 'static, O: Ownership> Id<T, O> where
T::Super: 'static,
impl<T: ClassType + 'static, O: Ownership> Id<T, O> where
T::Super: 'static,
sourcepub fn into_super(this: Self) -> Id<T::Super, O>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
pub fn into_super(this: Self) -> Id<T::Super, O>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
Convert the object into it’s superclass.
Trait Implementations
sourceimpl<T> BorrowMut<T> for Id<T, Owned>
impl<T> BorrowMut<T> for Id<T, Owned>
sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T: BufRead + ?Sized> BufRead for Id<T, Owned>
impl<T: BufRead + ?Sized> BufRead for Id<T, Owned>
sourcefn fill_buf(&mut self) -> Result<&[u8]>
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
sourcefn consume(&mut self, amt: usize)
fn consume(&mut self, amt: 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
sourcefn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
sourcefn read_line(&mut self, buf: &mut String) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>
Read all bytes until a newline (the 0xA
byte) is reached, and append
them to the provided buffer. You do not need to clear the buffer before
appending. Read more
sourcefn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Check if the underlying Read
has any data left to be read. Read more
sourceimpl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Id<I, Owned>
impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Id<I, Owned>
sourcefn next_back(&mut self) -> Option<I::Item>
fn next_back(&mut self) -> Option<I::Item>
Removes and returns an element from the end of the iterator. Read more
sourcefn nth_back(&mut self, n: usize) -> Option<I::Item>
fn nth_back(&mut self, n: usize) -> Option<I::Item>
Returns the n
th element from the end of the iterator. Read more
sourcefn advance_back_by(&mut self, n: usize) -> Result<(), usize>
fn advance_back_by(&mut self, n: usize) -> Result<(), usize>
iter_advance_by
)Advances the iterator from the back by n
elements. Read more
1.27.0 · sourcefn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where
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
sourceimpl<T: ?Sized, O: Ownership> Drop for Id<T, O>
impl<T: ?Sized, O: Ownership> Drop for Id<T, O>
#[may_dangle]
(see this) doesn’t apply here since we
don’t run T
’s destructor (rather, we want to discourage having T
s with
a destructor); and even if we did run the destructor, it would not be safe
to add since we cannot verify that a dealloc
method doesn’t access
borrowed data.
sourceimpl<T: Error + ?Sized, O: Ownership> Error for Id<T, O>
impl<T: Error + ?Sized, O: Ownership> Error for Id<T, O>
sourcefn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · sourcefn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
sourceimpl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Id<I, Owned>
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Id<I, Owned>
sourceimpl<T: Message, O: Ownership> Extend<Id<T, O>> for NSMutableArray<T, O>
impl<T: Message, O: Ownership> Extend<Id<T, O>> for NSMutableArray<T, O>
sourcefn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T: Message + PartialEq, O: Ownership> Extend<Id<T, O>> for NSMutableSet<T, O>
impl<T: Message + PartialEq, O: Ownership> Extend<Id<T, O>> for NSMutableSet<T, O>
sourcefn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T: Hasher + ?Sized> Hasher for Id<T, Owned>
impl<T: Hasher + ?Sized> Hasher for Id<T, Owned>
sourcefn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
Writes a single u128
into this hasher.
sourcefn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
Writes a single usize
into this hasher.
sourcefn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
Writes a single i128
into this hasher.
sourcefn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
Writes a single isize
into this hasher.
sourcefn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)Writes a length prefix into this hasher, as part of being prefix-free. Read more
sourceimpl<I: Iterator + ?Sized> Iterator for Id<I, Owned>
impl<I: Iterator + ?Sized> Iterator for Id<I, Owned>
sourcefn next(&mut self) -> Option<I::Item>
fn next(&mut self) -> Option<I::Item>
Advances the iterator and returns the next value. Read more
sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. Read more
sourcefn nth(&mut self, n: usize) -> Option<I::Item>
fn nth(&mut self, n: usize) -> Option<I::Item>
Returns the n
th element of the iterator. Read more
sourcefn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
iter_next_chunk
)Advances the iterator and returns an array containing the next N
values. Read more
1.0.0 · sourcefn count(self) -> usize
fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. Read more
1.0.0 · sourcefn last(self) -> Option<Self::Item>
fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. Read more
sourcefn advance_by(&mut self, n: usize) -> Result<(), usize>
fn advance_by(&mut self, n: usize) -> Result<(), usize>
iter_advance_by
)Advances the iterator by n
elements. Read more
1.28.0 · sourcefn step_by(self, step: usize) -> StepBy<Self>
fn step_by(self, step: usize) -> StepBy<Self>
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
1.0.0 · sourcefn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator<Item = Self::Item>,
Takes two iterators and creates a new iterator over both in sequence. Read more
1.0.0 · sourcefn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> where
U: IntoIterator,
‘Zips up’ two iterators into a single iterator of pairs. Read more
sourcefn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> where
G: FnMut() -> Self::Item,
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> where
G: FnMut() -> Self::Item,
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 · sourcefn map<B, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> B,
Takes a closure and creates an iterator which calls that closure on each element. Read more
1.21.0 · sourcefn for_each<F>(self, f: F) where
F: FnMut(Self::Item),
fn for_each<F>(self, f: F) where
F: FnMut(Self::Item),
Calls a closure on each element of an iterator. Read more
1.0.0 · sourcefn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
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 · sourcefn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<B>,
Creates an iterator that both filters and maps. Read more
1.0.0 · sourcefn enumerate(self) -> Enumerate<Self>
fn enumerate(self) -> Enumerate<Self>
Creates an iterator which gives the current iteration count as well as the next value. Read more
1.0.0 · sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
1.0.0 · sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Creates an iterator that yields elements based on a predicate. Read more
1.57.0 · sourcefn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> where
P: FnMut(Self::Item) -> Option<B>,
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> where
P: FnMut(Self::Item) -> Option<B>,
Creates an iterator that both yields elements based on a predicate and maps. Read more
1.0.0 · sourcefn skip(self, n: usize) -> Skip<Self>
fn skip(self, n: usize) -> Skip<Self>
Creates an iterator that skips the first n
elements. Read more
1.0.0 · sourcefn take(self, n: usize) -> Take<Self>
fn take(self, n: usize) -> Take<Self>
Creates an iterator that yields the first n
elements, or fewer
if the underlying iterator ends sooner. Read more
1.0.0 · sourcefn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
F: FnMut(&mut St, Self::Item) -> Option<B>,
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 · sourcefn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
U: IntoIterator,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
U: IntoIterator,
F: FnMut(Self::Item) -> U,
Creates an iterator that works like map, but flattens nested structure. Read more
1.0.0 · sourcefn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
Does something with each element of an iterator, passing the value on. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. Read more
1.0.0 · sourcefn collect<B>(self) -> B where
B: FromIterator<Self::Item>,
fn collect<B>(self) -> B where
B: FromIterator<Self::Item>,
Transforms an iterator into a collection. Read more
sourcefn collect_into<E>(self, collection: &mut E) -> &mut E where
E: Extend<Self::Item>,
fn collect_into<E>(self, collection: &mut E) -> &mut E where
E: Extend<Self::Item>,
iter_collect_into
)Collects all the items from an iterator into a collection. Read more
1.0.0 · sourcefn partition<B, F>(self, f: F) -> (B, B) where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
fn partition<B, F>(self, f: F) -> (B, B) where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
Consumes an iterator, creating two collections from it. Read more
sourcefn is_partitioned<P>(self, predicate: P) -> bool where
P: FnMut(Self::Item) -> bool,
fn is_partitioned<P>(self, predicate: P) -> bool where
P: FnMut(Self::Item) -> bool,
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 · sourcefn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where
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 · sourcefn try_for_each<F, R>(&mut self, f: F) -> R where
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
fn try_for_each<F, R>(&mut self, f: F) -> R where
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 · sourcefn fold<B, F>(self, init: B, f: F) -> B where
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> B where
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 · sourcefn reduce<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(Self::Item, Self::Item) -> Self::Item,
fn reduce<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(Self::Item, Self::Item) -> Self::Item,
Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
sourcefn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType where
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType where
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
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 · sourcefn all<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
Tests if every element of the iterator matches a predicate. Read more
1.0.0 · sourcefn any<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
Tests if any element of the iterator matches a predicate. Read more
1.0.0 · sourcefn find<P>(&mut self, predicate: P) -> Option<Self::Item> where
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where
P: FnMut(&Self::Item) -> bool,
Searches for an element of an iterator that satisfies a predicate. Read more
1.30.0 · sourcefn find_map<B, F>(&mut self, f: F) -> Option<B> where
F: FnMut(Self::Item) -> Option<B>,
fn find_map<B, F>(&mut self, f: F) -> Option<B> where
F: FnMut(Self::Item) -> Option<B>,
Applies function to the elements of iterator and returns the first non-none result. Read more
sourcefn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType where
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType where
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
try_find
)Applies function to the elements of iterator and returns the first true result or the first error. Read more
1.0.0 · sourcefn position<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
Searches for an element in an iterator, returning its index. Read more
1.6.0 · sourcefn max_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
Returns the element that gives the maximum value from the specified function. Read more
1.15.0 · sourcefn max_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> Option<Self::Item> where
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 · sourcefn min_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item> where
B: Ord,
F: FnMut(&Self::Item) -> B,
Returns the element that gives the minimum value from the specified function. Read more
1.15.0 · sourcefn min_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> Option<Self::Item> where
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 · sourcefn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Iterator<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where
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
1.36.0 · sourcefn copied<'a, T>(self) -> Copied<Self> where
T: 'a + Copy,
Self: Iterator<Item = &'a T>,
fn copied<'a, T>(self) -> Copied<Self> where
T: 'a + Copy,
Self: Iterator<Item = &'a T>,
Creates an iterator which copies all of its elements. Read more
1.0.0 · sourcefn cloned<'a, T>(self) -> Cloned<Self> where
T: 'a + Clone,
Self: Iterator<Item = &'a T>,
fn cloned<'a, T>(self) -> Cloned<Self> where
T: 'a + Clone,
Self: Iterator<Item = &'a T>,
sourcefn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
iter_array_chunks
)Returns an iterator over N
elements of the iterator at a time. Read more
1.11.0 · sourcefn sum<S>(self) -> S where
S: Sum<Self::Item>,
fn sum<S>(self) -> S where
S: Sum<Self::Item>,
Sums the elements of an iterator. Read more
1.11.0 · sourcefn product<P>(self) -> P where
P: Product<Self::Item>,
fn product<P>(self) -> P where
P: Product<Self::Item>,
Iterates over the entire iterator, multiplying all the elements Read more
sourcefn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
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 · sourcefn partial_cmp<I>(self, other: I) -> Option<Ordering> where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
fn partial_cmp<I>(self, other: I) -> Option<Ordering> where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Lexicographically compares the elements of this Iterator
with those
of another. Read more
sourcefn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering> where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering> where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
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 · sourcefn eq<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
fn eq<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
sourcefn eq_by<I, F>(self, other: I, eq: F) -> bool where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
fn eq_by<I, F>(self, other: I, eq: F) -> bool where
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
iter_order_by
)1.5.0 · sourcefn ne<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
fn ne<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
1.5.0 · sourcefn lt<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
fn lt<I>(self, other: I) -> bool where
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
1.5.0 · sourcefn le<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
fn le<I>(self, other: I) -> bool where
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
1.5.0 · sourcefn gt<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
fn gt<I>(self, other: I) -> bool where
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
1.5.0 · sourcefn ge<I>(self, other: I) -> bool where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
fn ge<I>(self, other: I) -> bool where
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
sourcefn is_sorted_by<F>(self, compare: F) -> bool where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
fn is_sorted_by<F>(self, compare: F) -> bool where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
is_sorted
)Checks if the elements of this iterator are sorted using the given comparator function. Read more
sourcefn is_sorted_by_key<F, K>(self, f: F) -> bool where
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
fn is_sorted_by_key<F, K>(self, f: F) -> bool where
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
is_sorted
)Checks if the elements of this iterator are sorted using the given key extraction function. Read more
sourceimpl<'a, T: Message + ?Sized, O: Ownership> MessageReceiver for &'a Id<T, O>
impl<'a, T: Message + ?Sized, O: Ownership> MessageReceiver for &'a Id<T, O>
sourceunsafe fn send_message<A, R>(self, sel: Sel, args: A) -> R where
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> R where
A: MessageArguments,
R: EncodeConvert,
Sends a message to self with the given selector and arguments. Read more
sourceunsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> R where
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> R where
A: MessageArguments,
R: EncodeConvert,
Sends a message to a specific superclass with the given selector and arguments. Read more
sourceimpl<'a, T: Message + ?Sized> MessageReceiver for &'a mut Id<T, Owned>
impl<'a, T: Message + ?Sized> MessageReceiver for &'a mut Id<T, Owned>
sourceunsafe fn send_message<A, R>(self, sel: Sel, args: A) -> R where
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> R where
A: MessageArguments,
R: EncodeConvert,
Sends a message to self with the given selector and arguments. Read more
sourceunsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> R where
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> R where
A: MessageArguments,
R: EncodeConvert,
Sends a message to a specific superclass with the given selector and arguments. Read more
sourceimpl<T: Ord + ?Sized, O: Ownership> Ord for Id<T, O>
impl<T: Ord + ?Sized, O: Ownership> Ord for Id<T, O>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T: PartialEq + ?Sized, O: Ownership> PartialEq<Id<T, O>> for Id<T, O>
impl<T: PartialEq + ?Sized, O: Ownership> PartialEq<Id<T, O>> for Id<T, O>
sourceimpl<T: PartialOrd + ?Sized, O: Ownership> PartialOrd<Id<T, O>> for Id<T, O>
impl<T: PartialOrd + ?Sized, O: Ownership> PartialOrd<Id<T, O>> for Id<T, O>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
sourcefn lt(&self, other: &Self) -> bool
fn lt(&self, other: &Self) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
sourcefn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T: Read + ?Sized> Read for Id<T, Owned>
impl<T: Read + ?Sized> Read for Id<T, Owned>
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
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
sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Read all bytes until EOF in this source, placing them into buf
. Read more
sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
Read all bytes until EOF in this source, appending them to buf
. Read more
sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the exact number of bytes required to fill buf
. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
sourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill cursor
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl<T: Seek + ?Sized> Seek for Id<T, Owned>
impl<T: Seek + ?Sized> Seek for Id<T, Owned>
sourcefn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
sourcefn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Returns the current seek position from the start of the stream. Read more
sourceimpl<T: Write + ?Sized> Write for Id<T, Owned>
impl<T: Write + ?Sized> Write for Id<T, Owned>
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. Read more
sourcefn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
Writes a formatted string into this writer, returning any error encountered. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
impl<T: Eq + ?Sized, O: Ownership> Eq for Id<T, O>
impl<I: FusedIterator + ?Sized> FusedIterator for Id<I, Owned>
impl<T: RefUnwindSafe + ?Sized, O: Ownership> RefUnwindSafe for Id<T, O>
impl<T: Send + ?Sized> Send for Id<T, Owned>
Id<T, Owned>
are Send
if T
is Send
because they give the same
access as having a T directly.
The Send
implementation requires T: Sync
because Id<T, Shared>
give
access to &T
.
Additiontally, it requires T: Send
because if T: !Send
, you could
clone a Id<T, Shared>
, send it to another thread, and drop the clone
last, making dealloc
get called on the other thread, and violate
T: !Send
.
impl<T: Sync + ?Sized> Sync for Id<T, Owned>
Id<T, Owned>
are Sync
if T
is Sync
because they give the same
access as having a T
directly.
The Sync
implementation requires T: Sync
because &Id<T, Shared>
give
access to &T
.
Additiontally, it requires T: Send
, because if T: !Send
, you could
clone a &Id<T, Shared>
from another thread, and drop the clone last,
making dealloc
get called on the other thread, and violate T: !Send
.
impl<T: ?Sized, O: Ownership> Unpin for Id<T, O>
impl<T: UnwindSafe + ?Sized> UnwindSafe for Id<T, Owned>
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more