Skip to main content

CodexOkRaw

Struct CodexOkRaw 

Source
pub struct CodexOkRaw<T, C = HashMap<String, String>> {
    pub value: T,
    pub location: &'static Location<'static>,
    pub execution_meta: C,
}
Expand description

Detailed diagnostic information for a successful execution.

CodexOkRaw wraps the underlying success value and automatically captures the precise file and line number where the success was instantiated. It also provides a metadata envelope for injecting contextual data (e.g., execution time, row counts, or process IDs) into the success path.

§Type Parameters

  • T - The type of the successful value being wrapped.
  • C - The type of the execution metadata. Defaults to HashMap<String, String> for dynamic key-value pairs, but can be replaced with a strongly-typed struct for better observability.

§Fields

  • value - The underlying success outcome.
  • location - The source code location (file and line) of the CodexOkRaw instantiation. This field is ignored during serialization.
  • execution_meta - A container for diagnostic information associated with the successful execution.

§Examples

use cirious_codex_result::CodexOkRaw;
use std::collections::HashMap;

// Explicitly provide the type to guide the compiler's inference
let result: CodexOkRaw<&str, HashMap<String, String>> = CodexOkRaw::new("Operation complete")
    .with_meta("duration_ms", "42")
    .with_meta("affected_rows", "5");

assert_eq!(result.value, "Operation complete");
assert_eq!(result.execution_meta.get("duration_ms").unwrap(), "42");

Fields§

§value: T

The underlying successful value.

§location: &'static Location<'static>

The precise location in the source code where this success was created.

§execution_meta: C

Arbitrary key-value metadata associated with this successful execution.

Implementations§

Source§

impl<T, C> CodexOkRaw<T, C>

Source

pub fn new(value: T) -> Self
where C: Default,

Wraps the result in a success scenario, natively capturing the location.

This method uses the #[track_caller] attribute to ensure that the location captured is the site where CodexOkRaw::new was called, rather than the location inside the new function itself.

§Arguments
  • value - The successful outcome value to be wrapped.
Examples found in repository?
examples/basic_usage.rs (line 16)
12pub fn example_dynamic_metadata() {
13  println!("--- Dynamic Metadata Example ---");
14
15  // Explicitly annotate type to satisfy inference for HashMap
16  let result = CodexOk::new("Operation completed").with_meta("service", "auth");
17
18  println!("{result}");
19
20  #[cfg(feature = "serde")]
21  log_codex_ok(&result);
22}
Source§

impl<T, S: BuildHasher> CodexOkRaw<T, HashMap<String, String, S>>

Source

pub fn with_meta<K: Into<String>, V: Into<String>>( self, key: K, value: V, ) -> Self

Injects arbitrary execution metadata into the success envelope.

This method uses a builder-like pattern to allow chainable insertions of diagnostic metadata key-value pairs.

§Arguments
  • key - The metadata key (e.g., "duration_ms").
  • value - The string representation of the metadata value.
Examples found in repository?
examples/basic_usage.rs (line 16)
12pub fn example_dynamic_metadata() {
13  println!("--- Dynamic Metadata Example ---");
14
15  // Explicitly annotate type to satisfy inference for HashMap
16  let result = CodexOk::new("Operation completed").with_meta("service", "auth");
17
18  println!("{result}");
19
20  #[cfg(feature = "serde")]
21  log_codex_ok(&result);
22}

Trait Implementations§

Source§

impl<T: Debug, C: Debug> Debug for CodexOkRaw<T, C>

Source§

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

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

impl<'de, T, C> Deserialize<'de> for CodexOkRaw<T, C>
where CodexOkRaw<T, C>: Default, T: Deserialize<'de>, C: Deserialize<'de>,

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<T: Display, C> Display for CodexOkRaw<T, C>

Source§

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

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

impl<T, C> Serialize for CodexOkRaw<T, C>
where T: Serialize, C: Serialize,

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§

§

impl<T, C> Freeze for CodexOkRaw<T, C>
where T: Freeze, C: Freeze,

§

impl<T, C> RefUnwindSafe for CodexOkRaw<T, C>

§

impl<T, C> Send for CodexOkRaw<T, C>
where T: Send, C: Send,

§

impl<T, C> Sync for CodexOkRaw<T, C>
where T: Sync, C: Sync,

§

impl<T, C> Unpin for CodexOkRaw<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C> UnsafeUnpin for CodexOkRaw<T, C>
where T: UnsafeUnpin, C: UnsafeUnpin,

§

impl<T, C> UnwindSafe for CodexOkRaw<T, C>
where T: UnwindSafe, C: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.