#weak-references #reference #stable #unstable #documentation #rc-t #weak-t

rc

A copy of std::rc that runs on stable Rust with weak references

2 releases

Uses old Rust 2015

0.1.1 Jul 29, 2015
0.1.0 Jul 27, 2015

#22 in #weak-references

Download history 86/week @ 2024-03-24 102/week @ 2024-03-31 55/week @ 2024-04-07 90/week @ 2024-04-14 73/week @ 2024-04-21 72/week @ 2024-04-28 76/week @ 2024-05-05 65/week @ 2024-05-12 66/week @ 2024-05-19 57/week @ 2024-05-26 81/week @ 2024-06-02 41/week @ 2024-06-09 51/week @ 2024-06-16 52/week @ 2024-06-23 18/week @ 2024-06-30 20/week @ 2024-07-07

147 downloads per month

MIT/Apache

30KB
412 lines

rust-rc

A copy of the http://doc.rust-lang.org/std/rc/ module that runs on stable Rust with Weak references.

As of this writing, std::rc::Weak is marked #[unstable] and therefore can not be used on stable Rust yet.

To make this work, some features had to be removed:

  • Unsized / dynamically-sized types T are not supported in Rc<T> or Weak<T>
  • #[unsafe_no_drop_flag] is not used, so (in curent Rust) Rc<T> and Weak<T> have a drop flag and are two words big (16 bytes 64-bit platforms) instead of one.
  • NonZero is not used, so Option<Rc<T>> and Option<Weak<T>> are one word bigger than Rc<T> or Weak<T> (for a total of 24 bytes instead of 8 on 64-bit platforms).
  • std::intrinsics::assume is not used, so the optimizer may not be able to remove as many redundant checks.

Supporting both stable and unstable Rust

This crates has an unstable Cargo feature that makes it simply re-export std::rc, so that none of the above drawbacks apply.

If you want your own code to support both stable and unstable Rust, and get the size optimizations when available, use this crates as follows:

# Cargo.toml

[features]
unstable = ["rc/unstable"]

[dependencies]
rc = "0.1.1"
// lib.rs

#![cfg_attr(feature = "unstable", feature(rc_weak))]

extern crate rc;
// some_module.rs

use rc::{Rc, Weak};

No runtime deps

Features