Skip to main content

Crate asc

Crate asc 

Source
Expand description

Atomic Strong Count.

Asc is a lighter alternative to Arc for use cases that don’t need weak references. It provides shared, thread-safe ownership of heap-allocated data.

§Key differences from Arc

  • No Weak references — the allocation is freed as soon as the last Asc is dropped. This also means Asc cannot safely express reference cycles.
  • Custom allocators are not yet supported — Asc always uses the global allocator. This is blocked on the unstable allocator_api feature and will be reconsidered once it stabilizes.

§Cycle Warning

Asc does not have weak references. Any reference cycle (e.g., A → B → A) will cause a memory leak because the strong count never reaches zero. Asc is suitable for DAGs and tree structures; for general graphs with back-references, use Arc with Weak.

§Optional features

§Example

use asc::Asc;

let a: Asc<i32> = Asc::new(42);
let b = a.clone();

assert_eq!(Asc::strong_count(&a), 2);
assert_eq!(*b, 42);

// try_unwrap fails while other references exist
assert!(Asc::try_unwrap(a.clone()).is_err());

drop(b);

// try_unwrap succeeds with the last reference
let value = Asc::try_unwrap(a).unwrap();
assert_eq!(value, 42);

Structs§

Asc
Atomic Strong Count.