refptr
Macros, attributes, and traits for invasively reference-counted structs in Rust. See the documentation for more details.
Usage
Structs which support being referenced using RefPtr
are annotated with the
#[refcounted(...)]
attribute. This attribute generates the necessary unsafe
code, extra members, and trait implementations required.
Configuration
The reference counting behaviour of the target type is controlled using flags
passed to #[refcounted(...)]
. The following are the currently supported config
options:
-
atomic
- Use an atomic reference count, likestd::sync::Arc
. This is the default. -
nonatomic
- Use a non-atomic reference count, likestd::rc::Rc
. -
weak
- Adds support for weak references, which can be used to break cycles, likestd::sync::Weak
. -
finalize
- Types with this attribute cannot manually implementDrop
, as doing so would be unsound. If set, this will invoke a soundfinalize
method instead.Unlike
drop
,finalize
may be called multiple times if it causes a reference to the object to escape. Fields will be dropped as-usual.