Open wangbinyq opened 4 years ago
rust 中可以实现下面的方法吗?
pub trait Foo {
fn bar(self: Rc<dyn Foo>) -> Rc<dyn Foo> {
Rc::new(BarFoo { foo: self.clone() })
}
}
how to do placememt new. http://blakesmith.me/2018/12/31/what-is-placement-new-in-rust.html
std::alloc::alloc
std::mem::replace
, option::take
空指针在 rust 中的实现:
type EmptyPtr<T> = Option<Rc<T>>;
impl<T> EmptyPtr<T> {
pub fn is_null(&self) -> bool {
self.is_none()
}
pub fn set_null(&mut self) {
self.take()
// std::mem::replace(&mut self, None)
}
}
unsafe rust, raw pointer