bumpref

Crates.iobumpref
lib.rsbumpref
version0.1.0
created_at2025-11-14 01:06:11.429748+00
updated_at2025-11-14 01:06:11.429748+00
descriptionExplicit .bump() method for Arc and Rc that signals cheap refcount cloning
homepagehttps://github.com/corrode/bumpref
repositoryhttps://github.com/corrode/bumpref
max_upload_size
id1932107
size18,526
Matthias Endler (mre)

documentation

https://docs.rs/bumpref

README

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:

[dependencies]
bumpref = "0.1"

Then use it in your code:

extern crate bumpref;

use bumpref::Bump;
use std::sync::Arc;
use std::rc::Rc;

fn main() {
    // For Arc
    let arc = Arc::new(42);
    let arc_bumped = arc.bump(); // same as Arc::clone(&arc)

    // For Rc
    let rc = Rc::new("hello");
    let rc_bumped = rc.bump();

    // Also works with Weak references
    let weak = Arc::downgrade(&arc);
    let weak_bumped = weak.bump();
}

Supported Types

  • Arc<T> and std::sync::Weak<T>
  • Rc<T> and std::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.

Commit count: 0

cargo fmt