Skip to main content

TaskMessage

Struct TaskMessage 

Source
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

Source

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 implements Into<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.

Source

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 implements Into<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.

Source

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.

Source

pub fn level(&self) -> &MessageLevel

Returns the severity level of the message.

§Returns

A reference to the MessageLevel indicating the severity of this message.

Source

pub fn text(&self) -> &str

Returns the human-readable message text.

§Returns

A string slice containing the message text.

Source

pub fn code(&self) -> Option<&str>

Returns the machine-readable code, if available.

§Returns

Some(&str) if a code was set, None otherwise.

Source

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

Source§

fn clone(&self) -> TaskMessage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for TaskMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.