Macro reffers::rc_bit_mask
source · [−]macro_rules! rc_bit_mask {
($t: ty, $t_int: ty, $r:expr, $s: expr, $w: expr) => { ... };
}
Expand description
If you need your own rc with custom overhead, you can invoke this macro for your own type (which is normally a newtype around an integer).
Example
#[macro_use]
extern crate reffers;
use reffers::rc::Ref;
#[derive(Debug, Copy, Clone, Default)]
struct ManyWeak(u32);
// We want 16 Refs, no Strongs, and as many Weaks as possible
// for the 32 bits of overhead that we are willing to accept.
// In total, this must add up to max 30 bits (32 bits minus 2 for status).
rc_bit_mask!(ManyWeak, u32, 4, 0, 26);
fn main() {
let r: Ref<str, ManyWeak> = Ref::new_str("Hi!");
// We can create weaks
let w = r.get_weak();
// ...but no strongs
assert!(w.try_get_strong().is_err());
}