rust-obsolete

How would you implement a bi-directional linked list in Rust?

此生再无相见时 提交于 2019-11-27 13:01:56
问题 Note that this question refers to a version of Rust before Rust 1.0. Although the syntax has changed, the concepts are still valid. You can easily implement a forwards only linked list using owned pointers, something like: struct Node<T> { next: Option<~Node<T>>, data: T } Imagine, though, if you want to efficiently implement a queue that supports four basic operations: push : add to end of list pop : remove and return from the end of the list unshift : add to the front of the list shift :

Why “explicit lifetime bound required” for Box<T> in struct?

一世执手 提交于 2019-11-26 14:27:24
问题 Editor's note: This code no longer produces the same error after RFC 599 was implemented, but the concepts discussed in the answers are still valid. I'm trying to compile this code: trait A { fn f(&self); } struct S { a: Box<A>, } and I'm getting this error: a.rs:6:13: 6:14 error: explicit lifetime bound required a.rs:6 a: Box<A>, I want S.a to own an instance of A , and don't see how that lifetime is appropriate here. What do I need to do to make the compiler happy? My Rust version: rustc -