Struct FormatContext

Source
pub struct FormatContext { /* private fields */ }
Expand description

Context object for formatting Gordian Envelopes with annotations.

The FormatContext provides information about CBOR tags, known values, functions, and parameters that are used to annotate the output of envelope formatting functions. This context enables human-readable output when converting envelopes to string representations like diagnostic notation.

This type is central to the diagnostic capabilities of Gordian Envelope, translating numeric CBOR tags into meaningful names and providing context-specific formatting for special values.

§Format Context Content

A FormatContext contains:

  • CBOR tag registry (always present)
  • Known Values store (when known_value feature is enabled)
  • Functions store (when expression feature is enabled)
  • Parameters store (when expression feature is enabled)
  • A flag indicating whether the format should be flat or structured

§Global Context

A global format context is available through the with_format_context! and with_format_context_mut! macros. This global context is initialized with standard tags and registries.

§Example

Using the global format context to produce annotated CBOR diagnostic notation:

assert_eq!(e.diagnostic_annotated(),
indoc! {r#"
200(   / envelope /
    201("Hello.")   / leaf /
)
"#}.trim()
);

The annotations (comments after the / characters) provide human-readable context for the CBOR tags and structure.

Implementations§

Source§

impl FormatContext

Source

pub fn new( flat: bool, tags: Option<&TagsStore>, known_values: Option<&KnownValuesStore>, functions: Option<&FunctionsStore>, parameters: Option<&ParametersStore>, ) -> Self

Creates a new format context with the specified components.

This constructor allows full customization of the format context by providing optional components. Any component not provided will be initialized with its default.

§Parameters
  • flat - If true, formatting will be flattened without indentation and structure
  • tags - Optional CBOR tag registry for mapping tag numbers to names
  • known_values - Optional known values registry (requires known_value feature)
  • functions - Optional functions registry (requires expression feature)
  • parameters - Optional parameters registry (requires expression feature)
§Returns

A new FormatContext instance initialized with the provided components.

Source

pub fn is_flat(&self) -> bool

Returns whether flat formatting is enabled.

When flat formatting is enabled, envelope formatting functions produce more compact output without indentation and structural formatting.

Source

pub fn set_flat(self, flat: bool) -> Self

Sets whether flat formatting should be enabled and returns the modified context.

This method allows fluent-style modification of the context’s flat formatting setting.

§Parameters
  • flat - If true, flat formatting will be enabled
§Returns

A new FormatContext with the updated flat setting

Source

pub fn tags(&self) -> &TagsStore

Returns a reference to the CBOR tags registry.

The tags registry maps CBOR tag numbers to human-readable names and provides summarizers for tag-specific formatting.

Source

pub fn tags_mut(&mut self) -> &mut TagsStore

Returns a mutable reference to the CBOR tags registry.

This allows modifying the tags registry to add or change tag mappings.

Source

pub fn known_values(&self) -> &KnownValuesStore

Returns a reference to the known values registry.

The known values registry maps symbolic values (like “true”, “false”, etc.) to their canonical string representations.

This method is only available when the known_value feature is enabled.

Source

pub fn functions(&self) -> &FunctionsStore

Returns a reference to the functions registry.

The functions registry maps function identifiers to their human-readable names for use in expression formatting.

This method is only available when the expression feature is enabled.

Source

pub fn parameters(&self) -> &ParametersStore

Returns a reference to the parameters registry.

The parameters registry maps parameter identifiers to their human-readable names for use in expression formatting.

This method is only available when the expression feature is enabled.

Trait Implementations§

Source§

impl Clone for FormatContext

Source§

fn clone(&self) -> FormatContext

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for FormatContext

Default implementation for FormatContext, creating an instance with default components.

Source§

fn default() -> Self

Creates a default FormatContext with:

  • Flat formatting disabled (structured formatting)
  • Default tag registry
  • Default known values store (when known_value feature is enabled)
  • Default functions store (when expression feature is enabled)
  • Default parameters store (when expression feature is enabled)
Source§

impl TagsStoreTrait for FormatContext

Implementation of TagsStoreTrait for FormatContext, delegating to the internal TagsStore.

This implementation allows a FormatContext to be used anywhere a TagsStoreTrait is required, providing the tag resolution functionality directly.

Source§

fn assigned_name_for_tag(&self, tag: &Tag) -> Option<String>

Returns the assigned name for a tag if one exists.

Source§

fn name_for_tag(&self, tag: &Tag) -> String

Returns a name for a tag, either the assigned name or a generic representation.

Source§

fn tag_for_name(&self, name: &str) -> Option<Tag>

Looks up a tag by its name.

Source§

fn tag_for_value(&self, value: u64) -> Option<Tag>

Looks up a tag by its numeric value.

Source§

fn summarizer(&self, tag: TagValue) -> Option<&CBORSummarizer>

Returns a CBOR summarizer for a tag value if one exists.

Source§

fn name_for_value(&self, value: u64) -> String

Returns a name for a tag value, either the assigned name or a generic representation.

Source§

fn name_for_tag_opt<T>(tag: &Tag, tags: Option<&T>) -> String
where T: TagsStoreTrait, Self: Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T