In working on my latest project I've found this type (with T = u8
) very useful for parsing a binary format:
struct ArcSlice<T> {
underlying: Arc<[T]>,
start: usize,
end: usize,
}
Here's a playground with some key trait implementations and an example useful method. The idea is that ArcSlice { underlying, start, end }
acts like &underlying[start..end]
, only the Arc
gives you the extra ability to slice up the underlying memory without thinking about ownership or performing additional allocations. It's very similar to, and significantly inspired by, the bytes::Bytes
type, but it's significantly simpler and unsafe
-free because it sticks to a single "backend" for the underlying
field, whereas Bytes
allows you to use e.g. &'static [u8]
in place of Arc<[u8]>
.
I'm wondering whether those differences from Bytes
justify publishing this as a tiny crate. Is this something other people might conceivably find useful?