Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca59065

Browse files
Added a tree_node!() macro for TreeNode::new()
1 parent 705be81 commit ca59065

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

‎src/macros/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,29 @@ macro_rules! tree {
257257
}};
258258
}
259259

260+
/// ## Description
261+
///
262+
/// A macro that's used to make a new `TreeNode` element.
263+
///
264+
/// ## Match arms
265+
///
266+
/// Arm 1:
267+
/// - Takes an `i32` data type and makes a new `TreeNode` element out of it.
268+
///
269+
/// ## Example
270+
///
271+
/// ```rust
272+
/// use leetcode_trees_rs::utils::{tree_node, TreeNode};
273+
///
274+
/// assert_eq!(tree_node!(5), TreeNode::new(5));
275+
/// ```
276+
#[macro_export]
277+
macro_rules! tree_node {
278+
($val:expr) => {{
279+
$crate::utils::TreeNode::new($val)
280+
}};
281+
}
282+
260283
/// ## Description
261284
///
262285
/// A macro to reduce the boilerplate in generating symmetric binary trees.

‎src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ pub use crate::list_node;
2222
/// A re-export for the symmetric_tree!, right_tree! and left_tree! macros.
2323
/// All of the TreeNode macros can be used to also just generate a new `TreeNode` instance without
2424
/// expanding on it.
25-
pub use crate::{left_tree, right_tree, symmetric_tree, tree};
25+
pub use crate::{left_tree, right_tree, symmetric_tree, tree, tree_node};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /