Crates.io | bc-envelope-pattern |
lib.rs | bc-envelope-pattern |
version | 0.4.0 |
created_at | 2025-06-22 10:29:08.567157+00 |
updated_at | 2025-07-06 07:03:17.941203+00 |
description | Pattern matcher for Gordian Envelope |
homepage | |
repository | https://github.com/BlockchainCommons/bc-envelope-pattern-rust |
max_upload_size | |
id | 1721537 |
size | 648,491 |
Gordian Envelope is a structured format for hierarchical binary data focused on privacy. The Rust implementation provides a feature-rich, production-ready reference implementation.
Envelopes are designed to facilitate "smart documents" with a number of unique features:
This crate provides a pattern matcher and text syntax pattern parser for Gordian Envelope, allowing you to match specific structures within envelopes.
[dependencies]
bc-envelope-pattern = "0.4.0"
Unlike regular expressions which match sequential characters in strings, Gordian Envelope patterns match sequential elements of envelope trees. Therefore a given pattern can match multiple paths from the root of the envelope, and hence the matcher can return multiple matches.
This crate provides two APIs for creating Pattern
objects:
Pattern
type has many functions for creating various kinds of patterns. For example, the Pattern::any_text()
function creates a pattern that matches any text value, while the Pattern::cbor()
function creates a pattern that matches a given CBOR value.Pattern
objects using Pattern::parse()
, which takes a string containing the pattern and returns a Pattern
object or an error if the pattern is invalid.Once you have a Pattern
object, you can use it to match against Gordian Envelope structures.
Pattern::match()
function takes an Envelope
and returns a simple boolean indicating whether the pattern matches the envelope.Pattern::paths()
returns a Vec<Path>
containing the paths that match the pattern within the envelope. Each Path
is a Vec<Envelope>
representing a sequential traversal of envelopes that match the pattern, starting from the root of the envelope.Pattern::paths_with_captures()
returns the same Vec<Path>
but also another set of paths for each named capture in the pattern. This allows you to extract specific parts of the envelope that match named captures in the pattern.The format_paths()
and format_paths_opt()
functions allow you to format paths in various ways, such as as URs, summaries, or just the last element of each path. This is useful for displaying the results of pattern matching in a human-readable format.
The docs/envelope_patex.md file contains the specification for the pattern expression syntax used by this crate.
Further documentation is forthcoming and will be added to the docs/
directory.
The envelope
command-line tool provides a powerful interface for working with Gordian Envelope patterns. You can use it to match patterns against envelopes, extract data, and format the output in various ways.