bumpref
A lightweight Rust crate that provides a bump() method for reference-counted pointers.
This is an explicit alias for clone() that makes it clear the operation is cheap (just incrementing a reference count).
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Then use it in your code:
extern crate bumpref;
use Bump;
use Arc;
use Rc;
Supported Types
Arc<T>andstd::sync::Weak<T>Rc<T>andstd::rc::Weak<T>
All implementations work with T: ?Sized, so they support trait objects and slices.
Why?
When code contains many .clone() calls on reference-counted types, it's not immediately obvious whether you're doing an expensive deep clone or just bumping a refcount. Using .bump() makes the intent explicit and signals to readers that the operation is O(1).
Inspiration
This came out of a conversation with Richard Feldman on the 'Rust in Production' podcast about how Zed uses reference-counted pointers extensively in their codebase and how Richard was initially concerned that cloning datastructures might be expensive until learning that all those clones were just bumping reference counts. The interview is here.