Ark

Struct Ark 

Source
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>

Source

pub fn from_entries<E>(entries: impl IntoIterator<Item = E>) -> Self
where E: Into<Entry<C>>,

Read entries into Ark format.

Source

pub fn to_entries(self) -> Vec<(IPR, Attrs, Contents<C>)>
where Vec<C>: Clone,

Turn this Ark into a Vec of entries.

Source§

impl<C> Ark<C>
where C: Temporizable,

Source

pub fn import_files(self, db: &DB) -> Result<Ark<Digest>>

Import files into an on-disk database.

Source

pub fn import(self, db: &DB) -> Result<Digest>

Import files and serialized self into DB.

Source§

impl Ark<PathBuf>

Source

pub fn read(self) -> Result<Ark<Vec<u8>>>

Fetch file contents from disk into memory.

Be warned that this may be a very bad idea if the directory is larger than you have RAM for.

Source§

impl Ark<PathBuf>

Source

pub fn scan(base: impl AsRef<Path>) -> Result<Self>

Fetch metadata for a directory into memory.

This isn’t a parallel process, but it’s fast, and allows subsequent steps to load in a high-performance parallel way.

Examples found in repository?
examples/copy_source.rs (line 5)
4fn main() -> Result<()> {
5    Ark::scan("./src")?.write("./copy_of_src")?;
6    Ok(())
7}
Source§

impl<C> Ark<C>

Source

pub fn from_translation<SRC>(src: Ark<SRC>) -> Self
where C: From<SRC>, SRC: Clone,

Easy conversion by content type.

Source§

impl Ark<PathBuf>

Source

pub fn write(&self, dest: impl AsRef<Path>) -> Result<()>

Write files to a directory.

TODO: Permissions

Examples found in repository?
examples/copy_source.rs (line 5)
4fn main() -> Result<()> {
5    Ark::scan("./src")?.write("./copy_of_src")?;
6    Ok(())
7}
Source§

impl<C> Ark<C>

Source

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.
Source

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 to ark.paths()[N].
Source

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 to ark.paths()[N].
Source

pub fn len(&self) -> usize

Number of entries in this Ark.

Source

pub fn files<'a>(&'a self) -> FileIterator<'a, C>

Iterate the files in an Archive

Source

pub fn dirs<'a>(&'a self) -> DirIterator<'a, C>

Iterate the dirs in an Archive

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<C: Clone> Clone for Ark<C>

Source§

fn clone(&self) -> Ark<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug> Debug for Ark<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, C> Deserialize<'de> for Ark<C>
where C: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Ark<&str>> for Ark<String>

Source§

fn from(src: Ark<&str>) -> Self

Converts to this type from the input type.
Source§

impl From<Ark<&str>> for Ark<Vec<u8>>

Source§

fn from(src: Ark<&str>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Ark<C>> for Vec<(IPR, Attrs, Contents<C>)>
where Vec<C>: Clone,

Source§

fn from(src: Ark<C>) -> Self

Converts to this type from the input type.
Source§

impl From<Ark<String>> for Ark<Vec<u8>>

Source§

fn from(src: Ark<String>) -> Self

Converts to this type from the input type.
Source§

impl<C, S> From<Vec<(S, Attrs, Contents<C>)>> for Ark<C>
where S: Into<IPR>,

Source§

fn from(src: Vec<(S, Attrs, Contents<C>)>) -> Self

Converts to this type from the input type.
Source§

impl<C, S> From<Vec<(S, Contents<C>)>> for Ark<C>
where S: Into<IPR>,

Source§

fn from(src: Vec<(S, Contents<C>)>) -> Self

Converts to this type from the input type.
Source§

impl<C: PartialEq> PartialEq for Ark<C>

Source§

fn eq(&self, other: &Ark<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C> Save for Ark<C>
where Ark<C>: ToJson,

Source§

fn save(&self, db: &DB) -> Result<Digest>

Source§

impl<C> Serialize for Ark<C>
where C: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<C> ToJson for Ark<C>
where Ark<C>: Serialize,

Source§

impl<C> StructuralPartialEq for Ark<C>

Auto Trait Implementations§

§

impl<C> Freeze for Ark<C>

§

impl<C> RefUnwindSafe for Ark<C>
where C: RefUnwindSafe,

§

impl<C> !Send for Ark<C>

§

impl<C> !Sync for Ark<C>

§

impl<C> Unpin for Ark<C>

§

impl<C> UnwindSafe for Ark<C>
where C: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,