pub struct Ark<C>(/* private fields */);Expand description
Representation of an Archive.
Because this is generic, it can represent things like a directory on disk, allowing us to convert an Ark of on-disk files into an Ark of imported files in a simple, high-performance way. It obviates the need for things like a stream API, and allows for a lot of tests to be done in-memory without disk.
The underlying format is an SOA approach, which you can inspect with:
- ark.paths()
- ark.attrs()
- ark.contents()
These three channels are implemented as immutable, reference-counted vectors. This is great for memory hygiene! Almost every possible transformation you’d ever want to do on an Ark will leave one or two channels unchanged, and create a new vector for the stuff that is changing.
Implementations§
Source§impl<C> Ark<C>
impl<C> Ark<C>
Sourcepub fn from_entries<E>(entries: impl IntoIterator<Item = E>) -> Self
pub fn from_entries<E>(entries: impl IntoIterator<Item = E>) -> Self
Read entries into Ark format.
Source§impl<C> Ark<C>where
C: Temporizable,
impl<C> Ark<C>where
C: Temporizable,
Source§impl<C> Ark<C>
impl<C> Ark<C>
Sourcepub fn from_translation<SRC>(src: Ark<SRC>) -> Self
pub fn from_translation<SRC>(src: Ark<SRC>) -> Self
Easy conversion by content type.
Source§impl<C> Ark<C>
impl<C> Ark<C>
Sourcepub fn paths(&self) -> &Vec<IPR>
pub fn paths(&self) -> &Vec<IPR>
Internal paths list.
In an archive of length F+D, the following is guaranteed:
- This vector is length F+D.
- There are no duplicate paths.
- All files come before all directories.
- Within each of those sections, paths are sorted.
Sourcepub fn attrs(&self) -> &Vec<Attrs>
pub fn attrs(&self) -> &Vec<Attrs>
Internal attrs list.
In an archive of length F+D, the following is guaranteed:
- This vector is length F+D.
ark.attrs()[N]corresponds toark.paths()[N].
Sourcepub fn contents(&self) -> &Vec<C>
pub fn contents(&self) -> &Vec<C>
Internal contents list.
In an archive of length F+D, the following is guaranteed:
- This vector is length F, not F+D.
ark.contents()[N]corresponds toark.paths()[N].
Sourcepub fn files<'a>(&'a self) -> FileIterator<'a, C> ⓘ
pub fn files<'a>(&'a self) -> FileIterator<'a, C> ⓘ
Iterate the files in an Archive
Sourcepub fn dirs<'a>(&'a self) -> DirIterator<'a, C> ⓘ
pub fn dirs<'a>(&'a self) -> DirIterator<'a, C> ⓘ
Iterate the dirs in an Archive
Sourcepub fn compose(
paths: Rc<Vec<IPR>>,
attrs: Rc<Vec<Attrs>>,
contents: Rc<Vec<C>>,
) -> Self
pub fn compose( paths: Rc<Vec<IPR>>, attrs: Rc<Vec<Attrs>>, contents: Rc<Vec<C>>, ) -> Self
Slap together a new Ark from the constituent pieces.
Panics if length invariants aren’t fulfilled.
Sourcepub fn decompose(self) -> (Rc<Vec<IPR>>, Rc<Vec<Attrs>>, Rc<Vec<C>>)
pub fn decompose(self) -> (Rc<Vec<IPR>>, Rc<Vec<Attrs>>, Rc<Vec<C>>)
Break an Ark into its constituent components, moving them.
This is designed to pair with compose to allow you to reuse backing
memory while doing transformations. Usually you’ll only care about
transforming one, maybe two of the three channels.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty Ark.
Not as widely useful as you’d think, since Ark is efficient for bulk
operations, and not a great type for incremental mutability. Usually
you’ll want to work with a list of (path, attrs, Contents<C>) tuples for
poking around in little bits and pieces. These convert back and forth
with Arks very easily.