#[repr(transparent)]pub struct Id<T: ?Sized, O: Ownership> { /* private fields */ }
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§
source§impl<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)
.
source§impl<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)
.
source§impl<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>
pub unsafe fn cast<U: Message>(this: Self) -> Id<U, O>
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();
source§impl<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.
Trait Implementations§
source§impl<T> BorrowMut<T> for Id<T, Owned>
impl<T> BorrowMut<T> for Id<T, Owned>
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T: BufRead + ?Sized> BufRead for Id<T, Owned>
impl<T: BufRead + ?Sized> BufRead for Id<T, Owned>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresource§fn read_line(&mut self, buf: &mut String) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moresource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Read
has any data left to be read. Read moresource§impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Id<I, Owned>
impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Id<I, Owned>
source§fn next_back(&mut self) -> Option<I::Item>
fn next_back(&mut self) -> Option<I::Item>
source§fn nth_back(&mut self, n: usize) -> Option<I::Item>
fn nth_back(&mut self, n: usize) -> Option<I::Item>
n
th element from the end of the iterator. Read moresource§fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
iter_advance_by
)n
elements. Read more1.27.0 · source§fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,
Iterator::try_fold()
: it takes
elements starting from the back of the iterator. Read moresource§impl<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.
source§impl<T: Error + ?Sized, O: Ownership> Error for Id<T, O>
impl<T: Error + ?Sized, O: Ownership> Error for Id<T, O>
source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
source§impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Id<I, Owned>
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Id<I, Owned>
source§impl<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>
source§fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<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>
source§fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Id<T, O>>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T: Hasher + ?Sized> Hasher for Id<T, Owned>
impl<T: Hasher + ?Sized> Hasher for Id<T, Owned>
source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128
into this hasher.source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
usize
into this hasher.source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128
into this hasher.source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize
into this hasher.source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)source§impl<I: Iterator + ?Sized> Iterator for Id<I, Owned>
impl<I: Iterator + ?Sized> Iterator for Id<I, Owned>
source§fn next(&mut self) -> Option<I::Item>
fn next(&mut self) -> Option<I::Item>
source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
source§fn nth(&mut self, n: usize) -> Option<I::Item>
fn nth(&mut self, n: usize) -> Option<I::Item>
n
th element of the iterator. Read moresource§fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
fn next_chunk<const N: usize>( &mut self ) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where Self: Sized,
iter_next_chunk
)N
values. Read more1.0.0 · source§fn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere Self: Sized,
1.0.0 · source§fn last(self) -> Option<Self::Item>where
Self: Sized,
fn last(self) -> Option<Self::Item>where Self: Sized,
source§fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
iter_advance_by
)n
elements. Read more1.28.0 · source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where Self: Sized,
1.0.0 · source§fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where Self: Sized, U: IntoIterator<Item = Self::Item>,
1.0.0 · source§fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where Self: Sized, U: IntoIterator,
source§fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where
Self: Sized,
G: FnMut() -> Self::Item,
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where Self: Sized, G: FnMut() -> Self::Item,
iter_intersperse
)separator
between adjacent items of the original iterator. Read more1.0.0 · source§fn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F>where Self: Sized, F: FnMut(Self::Item) -> B,
1.21.0 · source§fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F)where Self: Sized, F: FnMut(Self::Item),
1.0.0 · source§fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
1.0.0 · source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where Self: Sized, F: FnMut(Self::Item) -> Option<B>,
1.0.0 · source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where Self: Sized,
1.0.0 · source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
1.0.0 · source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
1.57.0 · source§fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where Self: Sized, P: FnMut(Self::Item) -> Option<B>,
1.0.0 · source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where Self: Sized,
n
elements. Read more1.0.0 · source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where Self: Sized,
n
elements, or fewer
if the underlying iterator ends sooner. Read more1.0.0 · source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,
1.0.0 · source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,
1.0.0 · source§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F>where Self: Sized, F: FnMut(&Self::Item),
1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
1.0.0 · source§fn collect<B>(self) -> Bwhere
B: FromIterator<Self::Item>,
Self: Sized,
fn collect<B>(self) -> Bwhere B: FromIterator<Self::Item>, Self: Sized,
source§fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere E: Extend<Self::Item>, Self: Sized,
iter_collect_into
)1.0.0 · source§fn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
fn partition<B, F>(self, f: F) -> (B, B)where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool,
source§fn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn is_partitioned<P>(self, predicate: P) -> boolwhere Self: Sized, P: FnMut(Self::Item) -> bool,
iter_is_partitioned
)true
precede all those that return false
. Read more1.27.0 · source§fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,
1.27.0 · source§fn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
fn try_for_each<F, R>(&mut self, f: F) -> Rwhere Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Output = ()>,
1.0.0 · source§fn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> Bwhere Self: Sized, F: FnMut(B, Self::Item) -> B,
1.51.0 · source§fn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
fn reduce<F>(self, f: F) -> Option<Self::Item>where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,
source§fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_reduce<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere Self: Sized, F: FnMut(Self::Item, Self::Item) -> R, R: Try<Output = Self::Item>, <R as Try>::Residual: Residual<Option<Self::Item>>,
iterator_try_reduce
)1.0.0 · source§fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> bool,
1.0.0 · source§fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> bool,
1.0.0 · source§fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where Self: Sized, P: FnMut(&Self::Item) -> bool,
1.30.0 · source§fn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<B, F>(&mut self, f: F) -> Option<B>where Self: Sized, F: FnMut(Self::Item) -> Option<B>,
source§fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_find<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere Self: Sized, F: FnMut(&Self::Item) -> R, R: Try<Output = bool>, <R as Try>::Residual: Residual<Option<Self::Item>>,
try_find
)1.0.0 · source§fn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> Option<usize>where Self: Sized, P: FnMut(Self::Item) -> bool,
1.6.0 · source§fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,
1.15.0 · source§fn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> Option<Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.6.0 · source§fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,
1.15.0 · source§fn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> Option<Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.0.0 · source§fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item = (A, B)>,
1.36.0 · source§fn copied<'a, T>(self) -> Copied<Self>where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
fn copied<'a, T>(self) -> Copied<Self>where T: 'a + Copy, Self: Sized + Iterator<Item = &'a T>,
1.0.0 · source§fn cloned<'a, T>(self) -> Cloned<Self>where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + Clone, Self: Sized + Iterator<Item = &'a T>,
source§fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where Self: Sized,
iter_array_chunks
)N
elements of the iterator at a time. Read more1.11.0 · source§fn sum<S>(self) -> Swhere
Self: Sized,
S: Sum<Self::Item>,
fn sum<S>(self) -> Swhere Self: Sized, S: Sum<Self::Item>,
1.11.0 · source§fn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
fn product<P>(self) -> Pwhere Self: Sized, P: Product<Self::Item>,
source§fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · source§fn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn partial_cmp<I>(self, other: I) -> Option<Ordering>where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
PartialOrd
elements of
this Iterator
with those of another. The comparison works like short-circuit
evaluation, returning a result without comparing the remaining elements.
As soon as an order can be determined, the evaluation stops and a result is returned. Read moresource§fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · source§fn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn eq<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,
source§fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
iter_order_by
)1.5.0 · source§fn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn ne<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,
1.5.0 · source§fn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn lt<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
Iterator
are lexicographically
less than those of another. Read more1.5.0 · source§fn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn le<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
Iterator
are lexicographically
less or equal to those of another. Read more1.5.0 · source§fn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn gt<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
Iterator
are lexicographically
greater than those of another. Read more1.5.0 · source§fn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn ge<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
Iterator
are lexicographically
greater than or equal to those of another. Read moresource§fn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
fn is_sorted_by<F>(self, compare: F) -> boolwhere Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
is_sorted
)source§fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> K, K: PartialOrd<K>,
is_sorted
)source§impl<'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>
source§unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Rwhere
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Rwhere A: MessageArguments, R: EncodeConvert,
source§unsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> Rwhere
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_super_message<A, R>( self, superclass: &Class, sel: Sel, args: A ) -> Rwhere A: MessageArguments, R: EncodeConvert,
source§impl<'a, T: Message + ?Sized> MessageReceiver for &'a mut Id<T, Owned>
impl<'a, T: Message + ?Sized> MessageReceiver for &'a mut Id<T, Owned>
source§unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Rwhere
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Rwhere A: MessageArguments, R: EncodeConvert,
source§unsafe fn send_super_message<A, R>(
self,
superclass: &Class,
sel: Sel,
args: A
) -> Rwhere
A: MessageArguments,
R: EncodeConvert,
unsafe fn send_super_message<A, R>( self, superclass: &Class, sel: Sel, args: A ) -> Rwhere A: MessageArguments, R: EncodeConvert,
source§impl<T: Ord + ?Sized, O: Ownership> Ord for Id<T, O>
impl<T: Ord + ?Sized, O: Ownership> Ord for Id<T, O>
source§impl<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>
source§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<T: Read + ?Sized> Read for Id<T, Owned>
impl<T: Read + ?Sized> Read for Id<T, Owned>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl<T: Seek + ?Sized> Seek for Id<T, Owned>
impl<T: Seek + ?Sized> Seek for Id<T, Owned>
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
source§impl<T: Write + ?Sized> Write for Id<T, Owned>
impl<T: Write + ?Sized> Write for Id<T, Owned>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)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
.