[][src]Struct fog_pack::checklist::Checklist

pub struct Checklist<T> { /* fields omitted */ }

A Checklist for validating an Entry.

The checklist can be iterated over, yielding a series of hashes and their associated ChecklistItem. Passing an item to a schema along with the document referred to by the hash allows it to be checked off the list. When all items have been checked off, calling complete will return the contained data. This may be a Vec from encoding an Entry, an Entry that was decoded, or nothihng if the purpose was purely validation.

Examples

Assuming there is a HashMap containing all documents, a function to encode and verify an entry could be:

fn encode_entry(e: Entry, schema: &mut Schema, db: &HashMap<Hash, Document>) -> 
    Result<Vec<u8>, ()>
{
    let mut checklist = schema.encode_entry(e).or(Err(()))?;
    // Fetch each document for verification, and fail if we don't have one
    for (h, item) in checklist.iter_mut() {
        if let Some(doc) = db.get(h) {
            schema.check_item(doc, item);
        }
        else {
            return Err(());
        }
    }
    checklist.complete()
}

Implementations

impl<T> Checklist<T>[src]

pub fn is_complete(&self) -> bool[src]

Check to see if the checklist is ready for completion.

pub fn complete(self) -> Result<T, ()>[src]

Complete the checklist and return the encoded Entry as a byte vector. Fails if the checklist was not completed.

pub fn iter(&self) -> Iter<Hash, ChecklistItem>[src]

Iterate over the checklist, yielding tuples of type (&Hash, &ChecklistItem).

pub fn iter_mut(&mut self) -> IterMut<Hash, ChecklistItem>[src]

Mutably iterate over the checklist, yielding tuples of type (&Hash, &mut ChecklistItem).

pub fn get(&self, h: &Hash) -> Option<&ChecklistItem>[src]

Fetch a specific checklist item by hash.

pub fn get_mut(&mut self, h: &Hash) -> Option<&mut ChecklistItem>[src]

Mutably fetch a specific checklist item by hash.

Auto Trait Implementations

impl<T> RefUnwindSafe for Checklist<T> where
    T: RefUnwindSafe

impl<T> Send for Checklist<T> where
    T: Send

impl<T> Sync for Checklist<T> where
    T: Sync

impl<T> Unpin for Checklist<T> where
    T: Unpin

impl<T> UnwindSafe for Checklist<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.