You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structFoo;implDropforFoo{fndrop(&mutself){println!("Drop Foo");}}structBar;implDropforBar{fndrop(&mutself){println!("Drop Bar");}}structContainer{foo:Foo,bar:Bar,}fnmain(){Container{foo:Foo,bar:Bar,};}// Prints “Drop Foo” and then “Drop Bar”
Experimentally, when Ouroboros gets involved, references are dropped before their referents, despite appearing after them in declaration order:
structFoo;implDropforFoo{fndrop(&mutself){println!("Drop Foo");}}structBar<'foo>(&'fooFoo);implDropforBar<'_>{fndrop(&mutself){println!("Drop Bar");}}#[ouroboros::self_referencing]structContainer{foo:Foo,#[borrows(foo)]#[covariant]bar:Bar<'this>,}fnmain(){ContainerBuilder{foo:Foo,bar_builder: |foo| Bar(foo)}.build();}// Prints “Drop Bar” and then “Drop Foo”
This is logical in the sense that a reference must be dropped before its referent; however, it is contrary to the usual drop order of struct fields, and it is also AFAICT not documented anywhere in the Ouroboros documentation. Is the drop order something I can rely on? Should it be documented somewhere?
The text was updated successfully, but these errors were encountered:
In standard Rust, without anything self-referential,
struct
fields are dropped in order of declaration:Experimentally, when Ouroboros gets involved, references are dropped before their referents, despite appearing after them in declaration order:
This is logical in the sense that a reference must be dropped before its referent; however, it is contrary to the usual drop order of struct fields, and it is also AFAICT not documented anywhere in the Ouroboros documentation. Is the drop order something I can rely on? Should it be documented somewhere?
The text was updated successfully, but these errors were encountered: