pub struct TaskMessage { /* private fields */ }Expand description
Represents a structured message generated during task execution.
TaskMessage captures detailed execution information with an associated severity level,
allowing tasks to emit structured logs, warnings, errors, and debug information during
execution. These messages provide a detailed execution trace that can be used for
debugging, auditing, and understanding task behavior beyond simple success or failure.
Messages can optionally include a machine-readable code for categorization and a timestamp indicating when the message was generated.
§Fields
-
level- The severity level of the message (Info, Warning, Error, Debug). -
text- The human-readable message text describing what occurred. -
code- An optional machine-readable code or identifier for categorizing or filtering messages (e.g., “CONFIG_001”, “WARN_DEPRECATED”). -
timestamp- An optional timestamp indicating when the message was generated.
§Example
use genja_core::task::{TaskMessage, MessageLevel};
use std::time::SystemTime;
let message = TaskMessage::new(MessageLevel::Warning, "Using deprecated API")
.with_code("WARN_DEPRECATED")
.with_timestamp(SystemTime::now());
assert_eq!(message.text(), "Using deprecated API");
assert_eq!(message.code(), Some("WARN_DEPRECATED"));Implementations§
Source§impl TaskMessage
impl TaskMessage
Sourcepub fn new(level: MessageLevel, text: impl Into<String>) -> Self
pub fn new(level: MessageLevel, text: impl Into<String>) -> Self
Creates a new TaskMessage with the specified severity level and message text.
This constructor initializes a TaskMessage with the provided level and text,
with no code or timestamp set. Additional metadata can be added using the
builder methods with_code() and with_timestamp().
§Parameters
level- The severity level of the message (Info, Warning, Error, or Debug).text- The human-readable message text. Can be any type that implementsInto<String>, such as&str,String, or other string-like types.
§Returns
A new TaskMessage instance with the specified level and text, and no code
or timestamp set.
Sourcepub fn with_code(self, code: impl Into<String>) -> Self
pub fn with_code(self, code: impl Into<String>) -> Self
Sets a machine-readable code for categorizing or filtering the message.
This is a builder method that consumes self and returns the modified instance,
allowing for method chaining. The code can be used to programmatically identify
specific types of messages or group related messages together.
§Parameters
code- A machine-readable code or identifier. Can be any type that implementsInto<String>, such as&str,String, or other string-like types. Common examples include “CONFIG_001”, “WARN_DEPRECATED”, or “ERR_TIMEOUT”.
§Returns
The modified TaskMessage instance with the code set.
Sourcepub fn with_timestamp(self, timestamp: SystemTime) -> Self
pub fn with_timestamp(self, timestamp: SystemTime) -> Self
Sets the timestamp indicating when the message was generated.
This is a builder method that consumes self and returns the modified instance,
allowing for method chaining. The timestamp helps track when events occurred
during task execution.
§Parameters
timestamp- The timestamp when the message was generated.
§Returns
The modified TaskMessage instance with the timestamp set.
Sourcepub fn level(&self) -> &MessageLevel
pub fn level(&self) -> &MessageLevel
Returns the severity level of the message.
§Returns
A reference to the MessageLevel indicating the severity of this message.
Sourcepub fn code(&self) -> Option<&str>
pub fn code(&self) -> Option<&str>
Returns the machine-readable code, if available.
§Returns
Some(&str) if a code was set, None otherwise.
Sourcepub fn timestamp(&self) -> Option<SystemTime>
pub fn timestamp(&self) -> Option<SystemTime>
Returns the timestamp when the message was generated, if available.
§Returns
Some(SystemTime) if a timestamp was set, None otherwise.
Trait Implementations§
Source§impl Clone for TaskMessage
impl Clone for TaskMessage
Source§fn clone(&self) -> TaskMessage
fn clone(&self) -> TaskMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more