Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Costa <filippo@sovlabs.io>
  • Loading branch information
neysofu committed Sep 15, 2023
1 parent 117b44d commit 56d7fc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions module-system/sov-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use scratchpad::*;
pub use sov_first_read_last_write_cache::cache::CacheLog;
use sov_rollup_interface::digest::Digest;
pub use storage::Storage;
use utils::AlignedVec;
pub use utils::AlignedVec;

pub use crate::witness::{ArrayWitness, TreeWitnessReader, Witness};

Expand Down Expand Up @@ -84,7 +84,8 @@ impl Prefix {
}
}

pub(crate) fn as_aligned_vec(&self) -> &AlignedVec {
/// Returns a reference to the [`AlignedVec`] containing the prefix.
pub fn as_aligned_vec(&self) -> &AlignedVec {
&self.prefix
}

Expand Down
12 changes: 8 additions & 4 deletions module-system/sov-state/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AlignedVec keeps a vec whose length is guaranteed to be aligned to 4 bytes.
// This makes certain operations cheaper in zk-context (concatenation)
/// A [`Vec`] of bytes whose length is guaranteed to be aligned to 4 bytes.
/// This makes certain operations cheaper in zk-context (namely, concatenation).
// TODO: Currently the implementation defaults to `stc::vec::Vec` see:
// https://github.com/Sovereign-Labs/sovereign-sdk/issues/47
#[derive(
Expand All @@ -20,12 +20,13 @@ impl AlignedVec {
/// The length of the chunks of the aligned vector.
pub const ALIGNMENT: usize = 4;

// Creates a new AlignedVec whose length is aligned to [Self::ALIGNMENT] bytes.
/// Creates a new [`AlignedVec`] whose length is aligned to
/// [`AlignedVec::ALIGNMENT`] bytes.
pub fn new(vector: Vec<u8>) -> Self {
Self { inner: vector }
}

// Extends self with the contents of the other AlignedVec.
/// Extends `self` with the contents of the other [`AlignedVec`].
pub fn extend(&mut self, other: &Self) {
// TODO check if the standard extend method does the right thing.
// debug_assert_eq!(
Expand All @@ -36,14 +37,17 @@ impl AlignedVec {
self.inner.extend(&other.inner);
}

/// Consumes `self` and returns the underlying [`Vec`] of bytes.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}

/// Returns the length in bytes of the prefix.
pub fn len(&self) -> usize {
self.inner.len()
}

/// Returns `true` if the prefix is empty, `false` otherwise.
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down

0 comments on commit 56d7fc2

Please sign in to comment.