Hi guys, maybe some of you faced this repo at the beginning or maybe it will be helpful for those, who like me, genuinely confused with this task. Since you are more skilled maybe you can explain me the spirit of this task or what intended to be done.
https://github.com/instrumentisto/rust-incubator/blob/main/1_concepts/1_2_box_pin/README.md .
General premise is understandable : i pinned the value-> value is moved -> I cannot call trait method on the value + it's not matching by self parameter.
Other pitfall that I can see is to avoid of pinning the reference, it will match SayHi trait parameter demand but will not actually pin value so I will be able to move it .
Other part is to show that some of the traits are working with pinned values to guarantee that value will not be moved out, some async parts dunno too stupid for that.
But I genuinely confused how can I squeeze out Pin to be able to call say_hi() on it and do not break pin semantic. I will really appreciate if you will take a look. Thanks a lot
fn main(){
let pinned = Box::pin(String::from("Hello"));
let as_ref = pinned.as_ref().say_hi();
}
trait SayHi: fmt::Debug {
fn say_hi(self: Pin<&Self>) {
println!("Hi from {:?}", self)
}
}
impl<T> SayHi for Box<T> where T: Debug{}
