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_valuefeature is enabled) - Functions store (when
expressionfeature is enabled) - Parameters store (when
expressionfeature 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
impl FormatContext
Sourcepub fn new(
flat: bool,
tags: Option<&TagsStore>,
known_values: Option<&KnownValuesStore>,
functions: Option<&FunctionsStore>,
parameters: Option<&ParametersStore>,
) -> Self
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 structuretags- Optional CBOR tag registry for mapping tag numbers to namesknown_values- Optional known values registry (requiresknown_valuefeature)functions- Optional functions registry (requiresexpressionfeature)parameters- Optional parameters registry (requiresexpressionfeature)
§Returns
A new FormatContext instance initialized with the provided components.
Sourcepub fn is_flat(&self) -> bool
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.
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.
Returns a mutable reference to the CBOR tags registry.
This allows modifying the tags registry to add or change tag mappings.
Sourcepub fn known_values(&self) -> &KnownValuesStore
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.
Sourcepub fn functions(&self) -> &FunctionsStore
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.
Sourcepub fn parameters(&self) -> &ParametersStore
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
impl Clone for FormatContext
Source§fn clone(&self) -> FormatContext
fn clone(&self) -> FormatContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for FormatContext
Default implementation for FormatContext, creating an instance with default components.
impl Default for FormatContext
Default implementation for FormatContext, creating an instance with default components.
Source§fn default() -> Self
fn default() -> Self
Creates a default FormatContext with:
- Flat formatting disabled (structured formatting)
- Default tag registry
- Default known values store (when
known_valuefeature is enabled) - Default functions store (when
expressionfeature is enabled) - Default parameters store (when
expressionfeature is enabled)
Source§impl TagsStoreTrait for FormatContext
Implementation of TagsStoreTrait for FormatContext, delegating to the internal TagsStore.
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>
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
fn name_for_tag(&self, tag: &Tag) -> String
Returns a name for a tag, either the assigned name or a generic representation.
Source§fn summarizer(&self, tag: TagValue) -> Option<&CBORSummarizer>
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
fn name_for_value(&self, value: u64) -> String
Returns a name for a tag value, either the assigned name or a generic representation.
fn name_for_tag_opt<T>(tag: &Tag, tags: Option<&T>) -> Stringwhere
T: TagsStoreTrait,
Self: Sized,
Auto Trait Implementations§
impl Freeze for FormatContext
impl !RefUnwindSafe for FormatContext
impl Send for FormatContext
impl Sync for FormatContext
impl Unpin for FormatContext
impl !UnwindSafe for FormatContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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