Skip to content

Commit

Permalink
chore(core): Add doc comments for node_count
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Nov 1, 2024
1 parent c005e5d commit 400c0ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 3 additions & 10 deletions core/src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,7 @@ impl MastNodeId {
value: u32,
mast_forest: &MastForest,
) -> Result<Self, DeserializationError> {
if (value as usize) < mast_forest.nodes.len() {
Ok(Self(value))
} else {
Err(DeserializationError::InvalidValue(format!(
"Invalid deserialized MAST node ID '{}', but only {} nodes in the forest",
value,
mast_forest.nodes.len(),
)))
}
Self::from_u32_with_node_count(value, mast_forest.nodes.len())
}

/// Returns a new [`MastNodeId`] from the given `value` without checking its validity.
Expand All @@ -537,7 +529,8 @@ impl MastNodeId {
}

/// Returns a new [`MastNodeId`] with the provided `id`, or an error if `id` is greater or equal
/// to `node_count`.
/// to `node_count`. The `node_count` is the total number of nodes in the [`MastForest`] for
/// which this ID is being constructed.
///
/// This function can be used when deserializing an id whose corresponding node is not yet in
/// the forest and [`Self::from_u32_safe`] would fail. For instance, when deserializing the ids
Expand Down
4 changes: 4 additions & 0 deletions core/src/mast/serialization/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl MastNodeInfo {
Self { ty, digest: mast_node.digest() }
}

/// Attempts to convert this [`MastNodeInfo`] into a [`MastNode`] for the given `mast_forest`.
///
/// The `node_count` is the total expected number of nodes in the [`MastForest`] **after
/// deserialization**.
pub fn try_into_mast_node(
self,
mast_forest: &MastForest,
Expand Down

0 comments on commit 400c0ac

Please sign in to comment.