rc-slice2
The rc-slice2 library provides RcSlice
and ArcSlice
types representing slices of array-like data structures contained within Rc
and Arc
. Supports raw arrays, boxed slices, Vec
, and SmallVec
(with feature smallvec
). Includes limited support for resizing the original array, to conserve memory.
The library is fully no_std
, and has zero unsafe
blocks. Every function is now fully tested with examples and thorough documentation.
What happened to rc_slice
?
rc-slice2
is the successor to the rc_slice
crate. Ownership was not transferred due to supply chain trust concerns. This crate's 0.3.1
version is fully backwards compatible with rc_slice 0.3.0
. Version 0.4.0
includes a minor breaking change, because the method of specifying generic parameters was changed. However, the behavior of the API is still backwards compatible.
Usage
= "0.4"
extern crate alloc;
use RcSlice;
use Rc;
use RcSlice as Rcs;
let buffer: = new;
// Supports all kinds of slicing during construction
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Behaves like any other slice.
let mut slice = new;
assert_eq!;
assert_eq!;
assert_eq!;
// The slice can shrink, and returns cut-off elements.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// If the original buffer can change size, and there is only one
// strong reference, then the buffer can be shrunk to the slice.
let buffer = new;
let mut slice = new;
assert_eq!;
// Fails because `buffer` is still alive.
assert_eq!;
let weak_buffer = downgrade;
drop;
// Success; only one strong reference. Original buffer has been shrunk.
assert_eq!;
let buffer = inner.clone;
assert_eq!;
// But weak references were not preserved.
assert_eq!;
License
rc-slice2 is released under the terms of the Apache License, version 2.0 (see LICENSE-APACHE) or the MIT license (see LICENSE-MIT), at your option.