Skip to main content

ExecutionContext

Struct ExecutionContext 

Source
pub struct ExecutionContext {
    pub duration_ms: u64,
    pub affected_rows: usize,
    pub process_id: u32,
}
Expand description

Represents the structured diagnostic context for a successful operation.

This struct is intended to be used as the generic metadata context C within a CodexOkRaw instance. It provides standard fields for tracking common performance and identity metrics across your application.

§Fields

  • duration_ms - The time taken for the operation to complete, in milliseconds.
  • affected_rows - The number of database rows, file records, or entities modified.
  • process_id - The unique identifier of the process or worker thread that performed the task.

Fields§

§duration_ms: u64

The time taken for the operation to complete, in milliseconds.

§affected_rows: usize

The number of database rows, file records, or entities modified.

§process_id: u32

The unique identifier of the process or worker thread that performed the task.

Implementations§

Source§

impl ExecutionContext

Source

pub fn new() -> Self

Creates a new ExecutionContext with default values.

This is the canonical way to create a default context when the default method is not directly accessible or for explicit clarity.

Examples found in repository?
examples/basic_usage.rs (line 28)
25pub fn example_typed_metadata() {
26  println!("\n--- Typed Metadata Example ---");
27
28  let ctx = ExecutionContext::new()
29    .with_duration(150)
30    .with_affected_rows(12)
31    .with_process_id(9982);
32
33  // Provide explicit type here so the compiler knows C is ExecutionContext
34  let result: CodexOkRaw<String, ExecutionContext> = CodexOkRaw {
35    value: "Batch processing completed".to_string(),
36    location: std::panic::Location::caller(),
37    execution_meta: ctx,
38  };
39
40  println!("{result}");
41
42  #[cfg(feature = "serde")]
43  log_codex_ok(&result);
44}
Source

pub const fn with_duration(self, duration_ms: u64) -> Self

Sets the duration of the operation.

Examples found in repository?
examples/basic_usage.rs (line 29)
25pub fn example_typed_metadata() {
26  println!("\n--- Typed Metadata Example ---");
27
28  let ctx = ExecutionContext::new()
29    .with_duration(150)
30    .with_affected_rows(12)
31    .with_process_id(9982);
32
33  // Provide explicit type here so the compiler knows C is ExecutionContext
34  let result: CodexOkRaw<String, ExecutionContext> = CodexOkRaw {
35    value: "Batch processing completed".to_string(),
36    location: std::panic::Location::caller(),
37    execution_meta: ctx,
38  };
39
40  println!("{result}");
41
42  #[cfg(feature = "serde")]
43  log_codex_ok(&result);
44}
Source

pub const fn with_affected_rows(self, affected_rows: usize) -> Self

Sets the number of affected rows.

Examples found in repository?
examples/basic_usage.rs (line 30)
25pub fn example_typed_metadata() {
26  println!("\n--- Typed Metadata Example ---");
27
28  let ctx = ExecutionContext::new()
29    .with_duration(150)
30    .with_affected_rows(12)
31    .with_process_id(9982);
32
33  // Provide explicit type here so the compiler knows C is ExecutionContext
34  let result: CodexOkRaw<String, ExecutionContext> = CodexOkRaw {
35    value: "Batch processing completed".to_string(),
36    location: std::panic::Location::caller(),
37    execution_meta: ctx,
38  };
39
40  println!("{result}");
41
42  #[cfg(feature = "serde")]
43  log_codex_ok(&result);
44}
Source

pub const fn with_process_id(self, process_id: u32) -> Self

Sets the process ID.

Examples found in repository?
examples/basic_usage.rs (line 31)
25pub fn example_typed_metadata() {
26  println!("\n--- Typed Metadata Example ---");
27
28  let ctx = ExecutionContext::new()
29    .with_duration(150)
30    .with_affected_rows(12)
31    .with_process_id(9982);
32
33  // Provide explicit type here so the compiler knows C is ExecutionContext
34  let result: CodexOkRaw<String, ExecutionContext> = CodexOkRaw {
35    value: "Batch processing completed".to_string(),
36    location: std::panic::Location::caller(),
37    execution_meta: ctx,
38  };
39
40  println!("{result}");
41
42  #[cfg(feature = "serde")]
43  log_codex_ok(&result);
44}

Trait Implementations§

Source§

impl Debug for ExecutionContext

Source§

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

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

impl Default for ExecutionContext

Source§

fn default() -> ExecutionContext

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ExecutionContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ExecutionContext

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> CodexOkWrap for T

Source§

fn into_codex(self) -> CodexOkRaw<T>

Wraps the current value into a CodexOkRaw, natively capturing the caller location.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, 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.