[][src]Trait libimagentryref::refstore::RefStore

pub trait RefStore<'a> {
    fn get_ref<RPG: UniqueRefPathGenerator, H: AsRef<str>>(
        &'a self,
        hash: H
    ) -> Result<Option<FileLockEntry<'a>>>;
fn create_ref<RPG: UniqueRefPathGenerator, A: AsRef<Path>>(
        &'a self,
        path: A
    ) -> Result<FileLockEntry<'a>>;
fn retrieve_ref<RPG: UniqueRefPathGenerator, A: AsRef<Path>>(
        &'a self,
        path: A
    ) -> Result<FileLockEntry<'a>>; }

A extensions for the Store to handle Ref objects

The RefStore handles refs using a UniqueRefPathGenerator. The UniqueRefPathGenerator, as it name suggests, generates unique StoreIds for a &Path. It is a functor &Path -> StoreId.

It provides three functions which are called in the following sequence:

  • The UniqueRefPathGenerator::collection() function is used for get the collection a StoreId should be in (The first element of the StoreId path)
  • The UniqueRefPathGenerator::unique_hash() gets the &Path which it then should generate a unique String for. How this is done does not matter. It can hash the Path itself, read the file and hash that or something else. It should be reproduceable, though.
  • These two parts are joined and put into a StoreId which the UniqueRefPathGenerator::postprocess_storeid() function is then allowed to postprocess (for example add more parts to the StoreId). The default implementation does nothing.

The StoreId which is generated is then used to carry out the actual action (reading, creating ...). If a entry is created, header information is set (that it is a ref, the hash which was just generated and the path of the referenced file)

Details

The UniqueRefPathGenerator is passed as type parameter to enforce some semantics:

  • The used UniqueRefPathGenerator is defined by the implementation rather than by the runtime of the program or some environment. Of course this is only a small hurdle to enforce this, but a hint.
  • The UniqueRefPathGenerator is a functor which does not carry state.

Required methods

fn get_ref<RPG: UniqueRefPathGenerator, H: AsRef<str>>(
    &'a self,
    hash: H
) -> Result<Option<FileLockEntry<'a>>>

fn create_ref<RPG: UniqueRefPathGenerator, A: AsRef<Path>>(
    &'a self,
    path: A
) -> Result<FileLockEntry<'a>>

fn retrieve_ref<RPG: UniqueRefPathGenerator, A: AsRef<Path>>(
    &'a self,
    path: A
) -> Result<FileLockEntry<'a>>

Loading content...

Implementations on Foreign Types

impl<'a> RefStore<'a> for Store[src]

Loading content...

Implementors

Loading content...