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).
Add this to your Cargo.toml:
[dependencies]
bumpref = "0.1"Then use it in your code:
externcrate bumpref;use bumpref::Bump;use std::sync::Arc;use std::rc::Rc;fnmain(){// For Arclet arc = Arc::new(42);let arc_bumped = arc.bump();// same as Arc::clone(&arc)// For Rclet rc = Rc::new("hello");let rc_bumped = rc.bump();// Also works with Weak referenceslet weak = Arc::downgrade(&arc);let weak_bumped = weak.bump();}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.
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).
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.