pub struct AstPattern {
pub subject: AstSubject,
pub elements: Vec<AstPattern>,
}Expand description
Abstract Syntax Tree representation of a Pattern
This is the minimal, language-agnostic output format from pattern-rs.
It mirrors the Pattern<Subject> structure exactly.
§Structure
subject: The value of this pattern (identity, labels, properties)elements: Child patterns (recursive structure)
§Examples
Simple node:
{
"subject": {
"identity": "alice",
"labels": ["Person"],
"properties": {"name": "Alice"}
},
"elements": []
}Subject pattern with elements:
{
"subject": {
"identity": "team",
"labels": ["Team"],
"properties": {}
},
"elements": [
{"subject": {"identity": "alice", ...}, "elements": []},
{"subject": {"identity": "bob", ...}, "elements": []}
]
}Fields§
§subject: AstSubjectThe subject (value) of this pattern
elements: Vec<AstPattern>Child patterns (elements)
Implementations§
Source§impl AstPattern
impl AstPattern
Source§impl AstPattern
impl AstPattern
Sourcepub fn to_pattern(&self) -> Result<Pattern<Subject>, String>
pub fn to_pattern(&self) -> Result<Pattern<Subject>, String>
Convert from native Pattern<Subject> to AST
This is the core conversion function that transforms the Rust Pattern structure into a JSON-serializable AST.
§Examples
use gram_codec::AstPattern;
use pattern_core::{Pattern, Subject, Symbol};
use std::collections::{HashSet, HashMap};
let subject = Subject {
identity: Symbol("alice".to_string()),
labels: HashSet::new(),
properties: HashMap::new(),
};
let pattern = Pattern::point(subject);
let ast = AstPattern::from_pattern(&pattern);
assert_eq!(ast.subject.identity, "alice");Convert from AST back to native Pattern<Subject>.
pub fn from_pattern(pattern: &Pattern<Subject>) -> Self
Trait Implementations§
Source§impl Clone for AstPattern
impl Clone for AstPattern
Source§fn clone(&self) -> AstPattern
fn clone(&self) -> AstPattern
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AstPattern
impl Debug for AstPattern
Source§impl<'de> Deserialize<'de> for AstPattern
impl<'de> Deserialize<'de> for AstPattern
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 PartialEq for AstPattern
impl PartialEq for AstPattern
Source§impl Serialize for AstPattern
impl Serialize for AstPattern
impl StructuralPartialEq for AstPattern
Auto Trait Implementations§
impl Freeze for AstPattern
impl RefUnwindSafe for AstPattern
impl Send for AstPattern
impl Sync for AstPattern
impl Unpin for AstPattern
impl UnsafeUnpin for AstPattern
impl UnwindSafe for AstPattern
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
Mutably borrows from an owned value. Read more