Cow without std
This commit is contained in:
parent
866a6bd78a
commit
20156d1ac9
1 changed files with 20 additions and 4 deletions
|
@ -2,8 +2,8 @@ use alloc::vec::Vec;
|
|||
use core::{
|
||||
iter::{self, FusedIterator},
|
||||
num::NonZero,
|
||||
ops::Deref,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use winter_utils::{Deserializable, DeserializationError, Serializable};
|
||||
|
||||
|
@ -253,10 +253,26 @@ impl From<SparseMerklePath> for Vec<RpoDigest> {
|
|||
// ITERATORS
|
||||
// ================================================================================================
|
||||
|
||||
enum Inner<'a, T> {
|
||||
Owned(T),
|
||||
Borrowed(&'a T),
|
||||
}
|
||||
|
||||
impl<'a, T> Deref for Inner<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match *self {
|
||||
Self::Borrowed(borrowed) => borrowed,
|
||||
Self::Owned(ref owned) => &owned,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator for [`SparseMerklePath`].
|
||||
pub struct SparseMerklePathIter<'p> {
|
||||
/// The "inner" value we're iterating over.
|
||||
path: Cow<'p, SparseMerklePath>,
|
||||
path: Inner<'p, SparseMerklePath>,
|
||||
|
||||
/// The depth a `next()` call will get. `next_depth == 0` indicates that the iterator has been
|
||||
/// exhausted.
|
||||
|
@ -304,7 +320,7 @@ impl IntoIterator for SparseMerklePath {
|
|||
fn into_iter(self) -> SparseMerklePathIter<'static> {
|
||||
let tree_depth = self.depth();
|
||||
SparseMerklePathIter {
|
||||
path: Cow::Owned(self),
|
||||
path: Inner::Owned(self),
|
||||
next_depth: tree_depth,
|
||||
}
|
||||
}
|
||||
|
@ -317,7 +333,7 @@ impl<'p> IntoIterator for &'p SparseMerklePath {
|
|||
fn into_iter(self) -> SparseMerklePathIter<'p> {
|
||||
let tree_depth = self.depth();
|
||||
SparseMerklePathIter {
|
||||
path: Cow::Borrowed(self),
|
||||
path: Inner::Borrowed(self),
|
||||
next_depth: tree_depth,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue