with_tags

Macro with_tags 

Source
macro_rules! with_tags {
    ($action:expr) => { ... };
}
Expand description

A macro for accessing the global tags store in a read-only manner.

This macro provides safe access to a global TagsStore instance that persists for the entire application lifetime. It executes the provided closure with a reference to the tags store.

§Use Cases

Use this macro when you need to:

  • Look up tag names or values
  • Access tag summarizers
  • Format diagnostic output with tag information
  • Resolve tags in any read-only operation

§Examples

use dcbor::prelude::*;
use std::sync::Arc;

// Use with_tags to access the global tags store in a read-only manner
let tag_name = with_tags!(|tags: &TagsStore| {
    // First, let's register a tag in the global store for demonstration
    if tags.tag_for_value(42).is_none() {
        // We don't have direct mutable access here, but in a real app
        // you would use with_tags_mut! to register tags first
        // This is just for demonstration purposes
    }

    // Look up a tag name by its value (could be "date" if standard tags are registered)
    // or the numeric value as a string if not registered
    tags.name_for_value(42)
});

// Verify we got some kind of tag name or value
assert!(!tag_name.is_empty());

§Thread Safety

This macro is thread-safe. The global tags store is protected by a mutex, and this macro acquires a read lock on that mutex.