pub enum NodeType {
Root,
Translation,
KeyPath,
CodeRef,
}Expand description
Type of node in the reference tree.
§Rust Book Reference
Chapter 10.2: Traits - Deriving Traits https://doc.rust-lang.org/book/ch10-02-traits.html#deriving-traits
Chapter 6.1: Defining an Enum https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
§Educational Notes - Derive Macros on Enums
This enum demonstrates multiple derived traits:
ⓘ
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeType { ... }What each trait provides:
-
Debug- Enablesprintln!("{:?}", node_type)- Essential for debugging and error messages
- Automatically formats enum variants
-
Clone- Enables.clone()method- Creates a deep copy of the enum value
- For enums without data, this is trivial
-
PartialEq- Enables==and!=operators- Compares enum variants for equality
Root == Rootis true,Root == Translationis false
-
Eq- Marker trait for full equality- Requires
PartialEqfirst - Indicates equality is reflexive, symmetric, and transitive
- Needed for using types as HashMap keys
- Requires
Why derive instead of manual implementation?
- Less code to write and maintain
- Compiler-generated code is correct and efficient
- Consistent behavior across the codebase
Variants§
Root
Root node containing the search text
Translation
Translation file entry
KeyPath
Full key path (e.g., “invoice.labels.add_new”)
CodeRef
Code reference where the key is used
Trait Implementations§
impl Eq for NodeType
impl StructuralPartialEq for NodeType
Auto Trait Implementations§
impl Freeze for NodeType
impl RefUnwindSafe for NodeType
impl Send for NodeType
impl Sync for NodeType
impl Unpin for NodeType
impl UnwindSafe for NodeType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more