在C++中(如果錯誤,請糾正我),通過常量引用的臨時綁定應該超過它所綁定的表達式。我認爲Rust也是如此,但在兩種不同的情況下,我得到了兩種不同的行爲。 考慮: struct A;
impl Drop for A { fn drop(&mut self) { println!("Drop A.") } }
struct B(*const A);
impl Drop for B { fn d
我正在用指針實現方式在不可變對象上實現裝飾器模式。基本上我的設置是這樣的 struct Object : ObjectBase {
void doSmth() override {
impl->doSmth();
}
// this is the function I'd like to implement
Object decorateWith