Skip to main content

value_object

Attribute Macro value_object 

Source
#[value_object]
Expand description

Add the conventional derive set for an immutable value object.

Applied to either a struct (named or tuple) or an enum. The macro merges the user’s existing derives with: Default, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, and (by default) Debug. Unlike [entity] or [domain_event] no fields, methods or trait impls are generated — value objects are intentionally minimal pieces of data.

§Attribute arguments

#[value_object(debug = <bool>)]

  • debug — disable the auto-derived Debug (defaults to true) when callers want to provide a manual implementation (e.g. to redact sensitive content).

§Examples

On a struct:

use eventide_macros::value_object;

#[value_object]
struct Money {
    amount: i64,
    currency: String,
}

On an enum (note the #[default] variant required by the derived Default):

use eventide_macros::value_object;

#[value_object]
enum Level {
    #[default]
    Low,
    High,
}

Disabling auto-Debug to write a redacting impl:

use eventide_macros::value_object;

#[value_object(debug = false)]
struct ApiKey(String);

impl std::fmt::Debug for ApiKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("ApiKey(<redacted>)")
    }
}