pub struct LeavesToRootValidator {
accepted_directories: HashMap<B3Digest, u64>,
pending_directories: HashSet<B3Digest>,
last_inserted_digest: Option<B3Digest>,
poison: bool,
}Expand description
A struct holding state while consuming a sequence of Directories in Leaves-To-Root order.
Validates that newly accepted directories only reference directories which have already been accepted before, and that the sizes attached alongside the pointers match the actual sizes. Commonly used when uploading a directory closure to a store.
Fields§
§accepted_directories: HashMap<B3Digest, u64>tracks inserted directories, and their sizes observed.
pending_directories: HashSet<B3Digest>tracks seen directories which are not yet referenced by parents. (root candidates)
last_inserted_digest: Option<B3Digest>Tracks the last received digest
poison: booltracks whether Self::finalize has been called, or an error has occured while trying to accept.
Implementations§
Source§impl LeavesToRootValidator
impl LeavesToRootValidator
pub fn new() -> Self
Sourcepub fn try_accept(&mut self, directory: &Directory) -> Result<(), OrderingError>
pub fn try_accept(&mut self, directory: &Directory) -> Result<(), OrderingError>
Accepts a directory if previously introduced, or returns an error if it’s unknown.
Sourcepub fn finalize(self) -> Result<(), OrderingError>
pub fn finalize(self) -> Result<(), OrderingError>
Should be called before Drop, to ensure there’s no introduced but unsent directories.
Sourcepub fn validate_stream<'s, S>(
directories: S,
) -> BoxStream<'s, Result<Directory, OrderingError>>
pub fn validate_stream<'s, S>( directories: S, ) -> BoxStream<'s, Result<Directory, OrderingError>>
This receives a stream of Directories, validating them to be in Leaves-To-Root order. If the order is correct, they are yielded wrapped in an Ok(). If not, we yield an error.
Trait Implementations§
Source§impl Default for LeavesToRootValidator
impl Default for LeavesToRootValidator
Source§fn default() -> LeavesToRootValidator
fn default() -> LeavesToRootValidator
Auto Trait Implementations§
impl Freeze for LeavesToRootValidator
impl RefUnwindSafe for LeavesToRootValidator
impl Send for LeavesToRootValidator
impl Sync for LeavesToRootValidator
impl Unpin for LeavesToRootValidator
impl UnwindSafe for LeavesToRootValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request