Skip to content

Commit 6d8a512

Browse files
committed
Add new method
1 parent 5a3c94a commit 6d8a512

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

sponge-cursor/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ impl<Rate: ArraySize> Default for SpongeCursor<Rate> {
3737
}
3838

3939
impl<Rate: ArraySize> SpongeCursor<Rate> {
40+
/// Create new cursor with the provided position.
41+
///
42+
/// Returns `None` if `pos` is bigger or equal to `Rate`.
43+
#[must_use]
44+
pub fn new(pos: u8) -> Option<Self> {
45+
if usize::from(pos) < Rate::USIZE {
46+
Some(Self {
47+
pos,
48+
_pd: PhantomData,
49+
})
50+
} else {
51+
None
52+
}
53+
}
54+
4055
/// Absorb bytes from `data` into a `u64`-based state using little ednian byte order.
4156
///
4257
/// Size of state MUST be greater or equal to `Rate`. Using an invalid `N` will result in

0 commit comments

Comments
 (0)