In the Rust Book, there's an example implementing the state pattern containing the following impl
block,
impl State for Draft {
fn request_review(self: Box<Self>) -> Box<dyn State> {
Box::new(PendingReview {})
}
}
Up until this point, the book has only used Self
, &Self
or &mut Self
as the type of self
, which led me to believe that these were the only types allowed. How is Box<Self>
allowed here when the impl
block is being defined on Draft
, not Box<Draft>
? Given a type MyType<T>
, can the type of self
for methods defined on Draft
be fn foo(self: MyType<Draft>)
? Is Box
special in some way?