Trait Receiver
pub trait Receiver: PointeeSized
Indicates that a struct can be used as a method receiver.
That is, a type can use this type as a type of self, like this:
# // This is currently compile_fail because the compiler-side parts
# // of arbitrary_self_types are not implemented
use std::ops::Receiver;
struct SmartPointer<T>(T);
impl<T> Receiver for SmartPointer<T> {
type Target = T;
}
struct MyContainedType;
impl MyContainedType {
fn method(self: SmartPointer<Self>) {
// ...
}
}
fn main() {
let ptr = SmartPointer(MyContainedType);
ptr.method();
}
This trait is blanket implemented for any type which implements
Deref, which includes stdlib pointer types like Box<T>,Rc<T>, &T,
and Pin<P>. For that reason, it's relatively rare to need to
implement this directly. You'll typically do this only if you need
to implement a smart pointer type which can't implement Deref; perhaps
because you're interfacing with another programming language and can't
guarantee that references comply with Rust's aliasing rules.
When looking for method candidates, Rust will explore a chain of possible
Receivers, so for example each of the following methods work:
use Box;
use Rc;
// Both `Box` and `Rc` (indirectly) implement Receiver
;
Associated Types
type Target: ?Sized;The target type on which the method may be called.
Implementors
impl<P, T> Receiver for AssertUnwindSafe<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for ByteStr where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for DropGuard<T, F> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for IoSlice<'a> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for IoSliceMut<'a> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for LazyCell<T, F> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for ManuallyDrop<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for Pin<Ptr> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for Ref<'b, T> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T> Receiver for RefMut<'b, T> where P: Deref<Target = T> + ?Sized, T: ?Sized,impl<P, T: ?Sized> Receiver for P where P: Deref<Target = T> + ?Sized,