Trait Receiver
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: TraitBound { trait_: Path { path: "Sized", id: Id(12), args: None }, generic_params: [], modifier: Maybe }The target type on which the method may be called.
Implementors
impl<P, T> Receiver for AssertUnwindSafe<T>impl<P, T> Receiver for ByteStrimpl<P, T> Receiver for RefMut<'b, T>impl<P, T> Receiver for DropGuard<T, F>impl<P, T> Receiver for Ref<'b, T>impl<P, T: ?Sized> Receiver for Pimpl<P, T> Receiver for Pin<Ptr>impl<P, T> Receiver for ManuallyDrop<T>impl<P, T> Receiver for LazyCell<T, F>