Rust Examples

Page 4 of 8

Browse Rust examples

rustSnippet

Shared Tree Nodes Rc RefCell

Let several parents share child nodes through Rc<RefCell<Vec>>: Rc clones share ownership without copying, RefCell mutates inside an immutable shell.

rustSnippet

Ordering Then With Lazy Ties

Order records with Ordering::then_with so the secondary comparison only runs when the primary keys tie, keeping expensive keys out of the hot path.

rustSnippet

Thread Park And Unpark Handoff

Hand a signal between threads with thread::park and Thread::unpark, which needs no channel and keeps an unpark that arrives before the park.

rustSnippet

Vec Splice Replace Range

Replace a middle range in place with Vec::splice, keep the removed elements, and reuse the same call with an empty iterator to delete.