Skip to content

Commit 826b3ab

Browse files
committed
panics and safety documentations added
1 parent 32a966c commit 826b3ab

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/common_traits/from_depth_first_iter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ where
219219
0 => {
220220
let tree = Tree::new_with_root(root);
221221

222+
// # SAFETY:
223+
// `push_dfs_under_root` panics if iter is empty. Therefore,
224+
//
225+
// * We first check if lower-bound(len) > 0, this allows us to directly use the iter
226+
// which is faster.
227+
// * Otherwise, we use a peekable iterator to make sure that the iterator has at least
228+
// one element.
222229
let (lb_len, _) = iter.size_hint();
223230

224231
match lb_len > 0 {
@@ -238,6 +245,9 @@ where
238245
}
239246
}
240247

248+
/// # Panics
249+
///
250+
/// Panics if the `iter` is an empty iterator. It must contain at least one child node.
241251
fn push_dfs_under_root<I, V, M, P>(
242252
mut tree: Tree<V, M, P>,
243253
iter: I,

src/node_mut.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,6 +3264,10 @@ where
32643264
/// greater than one.
32653265
/// The method returns the (depth, succeeding_depth) pair as the error when this error
32663266
/// is observed.
3267+
///
3268+
/// # Panics
3269+
///
3270+
/// Panics if the `subtree` is an empty iterator. It must contain at least one child node.
32673271
#[allow(clippy::unwrap_in_result)]
32683272
pub(crate) fn try_append_subtree_as_child(
32693273
&mut self,

0 commit comments

Comments
 (0)