named_item/
named.rs

1crate::ix!();
2
3/// Trait for getting the name of an item.
4pub trait Named {
5    /// Returns the name associated with `self`. 
6    /// We use `Cow` to allow both owned and borrowed strings.
7    fn name(&self) -> Cow<'_, str>;
8}
9
10/// Trait for setting the name of an item with error handling.
11pub trait SetName {
12    /// Sets the name of the item. Returns a Result to handle invalid inputs.
13    fn set_name(&mut self, name: &str) -> Result<(), NameError>;
14}
15
16/// Trait for providing a default name.
17pub trait DefaultName {
18    /// Returns the default name for an item. `Cow<'static, str>` allows owned or static string.
19    fn default_name() -> Cow<'static, str>;
20}
21
22/// Macro to create a name with an optional separator.
23#[macro_export]
24macro_rules! name {
25    ($prefix:expr, $suffix:expr, $sep:expr) => {
26        &format!("{}{}{}", $prefix, $sep, $suffix)
27    };
28    ($prefix:expr, $suffix:expr) => {
29        &format!("{}.{}", $prefix, $suffix)
30    };
31}