Skip to main content

Subject

Struct Subject 

Source
pub struct Subject {
    pub identity: Symbol,
    pub labels: HashSet<String>,
    pub properties: PropertyRecord,
}
Expand description

Self-descriptive object with identity, labels, and properties.

Subject is designed to be the primary content type for patterns (i.e., Pattern<Subject> will be the common use case).

A Subject contains:

  • Identity: A required symbol identifier that uniquely identifies the subject
  • Labels: A set of label strings that categorize or classify the subject
  • Properties: A key-value map storing properties with rich value types

Note: This type only implements PartialEq, not Eq, because it contains Value which uses f64 (f64 doesn’t implement Eq due to NaN != NaN).

§Examples

use pattern_core::{Subject, Symbol, Value};
use std::collections::{HashSet, HashMap};

let subject = Subject {
    identity: Symbol("n".to_string()),
    labels: {
        let mut s = HashSet::new();
        s.insert("Person".to_string());
        s
    },
    properties: {
        let mut m = HashMap::new();
        m.insert("name".to_string(), Value::VString("Alice".to_string()));
        m.insert("age".to_string(), Value::VInteger(30));
        m
    },
};

§Usage with Pattern

use pattern_core::{Pattern, Subject, Symbol};
use std::collections::HashSet;

let subject = Subject {
    identity: Symbol("n".to_string()),
    labels: HashSet::new(),
    properties: std::collections::HashMap::new(),
};

let pattern: Pattern<Subject> = Pattern {
    value: subject,
    elements: vec![],
};

Fields§

§identity: Symbol

Symbol identifier that uniquely identifies the subject.

The identity is always required. In gram notation, identities appear before labels and properties.

§labels: HashSet<String>

Set of label strings that categorize or classify the subject.

Labels provide classification information. The set can be empty (no labels) or contain one or more unique labels. In gram notation, labels are prefixed with : or :: and appear after the identity and before properties.

§properties: PropertyRecord

Key-value property map storing structured data about the subject.

Properties store attributes and metadata. The property record can be empty (no properties) or contain any number of key-value pairs. In gram notation, properties appear in curly braces: {name:"Alice", age:30}.

Implementations§

Source§

impl Subject

Source

pub fn from_id(identity: impl Into<String>) -> Subject

Creates an identity-only Subject with no labels or properties.

Useful as a reference handle when passing to methods that accept &Subject and only need the identity (e.g., add_relationship source/target args).

§Examples
use pattern_core::Subject;

let mut g = pattern_core::graph::StandardGraph::new();
let alice = Subject::build("alice").label("Person").done();
let bob   = Subject::build("bob").label("Person").done();
g.add_node(alice.clone());
g.add_node(bob.clone());
g.add_relationship(Subject::build("r1").label("KNOWS").done(), &alice, &bob);

// When you only have an ID string, use from_id as a lightweight reference:
g.add_relationship(
    Subject::build("r2").label("KNOWS").done(),
    &Subject::from_id("alice"),
    &Subject::from_id("bob"),
);
Source

pub fn build(identity: impl Into<String>) -> SubjectBuilder

Creates a SubjectBuilder with the given identity.

§Examples
use pattern_core::Subject;

let subject = Subject::build("alice")
    .label("Person")
    .property("name", "Alice")
    .done();
assert_eq!(subject.identity.0, "alice");
assert!(subject.labels.contains("Person"));

Trait Implementations§

Source§

impl Clone for Subject

Source§

fn clone(&self) -> Subject

Returns a duplicate 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 Combinable for Subject

Combination strategy for Subject that merges labels and properties.

This strategy combines two subjects by:

  • Using the identity from the first subject
  • Taking the union of labels from both subjects
  • Merging properties (values from the second subject overwrite the first)

§Semigroup Laws

This implementation satisfies associativity:

  • Identity choice is associative (always picks leftmost)
  • Label union is associative (set union is associative)
  • Property merge is associative with right-bias (latter values win)

§Examples

use pattern_core::{Subject, Symbol, Combinable};
use std::collections::{HashMap, HashSet};

let s1 = Subject {
    identity: Symbol("n1".to_string()),
    labels: {
        let mut s = HashSet::new();
        s.insert("Person".to_string());
        s
    },
    properties: HashMap::new(),
};

let s2 = Subject {
    identity: Symbol("n2".to_string()),
    labels: {
        let mut s = HashSet::new();
        s.insert("Employee".to_string());
        s
    },
    properties: HashMap::new(),
};

// Merge combines labels and uses first identity
let merged = s1.combine(s2);
assert_eq!(merged.identity.0, "n1");
assert!(merged.labels.contains("Person"));
assert!(merged.labels.contains("Employee"));
Source§

fn combine(self, other: Self) -> Self

Combines two values associatively. Read more
Source§

impl Debug for Subject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Subject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<SubjectBuilder> for Subject

Source§

fn from(builder: SubjectBuilder) -> Self

Converts to this type from the input type.
Source§

impl GraphValue for Subject

Source§

impl HasIdentity<Subject, Symbol> for Subject

Source§

impl Mergeable for Subject

Source§

type MergeStrategy = SubjectMergeStrategy

Source§

fn merge(strategy: &SubjectMergeStrategy, a: Subject, b: Subject) -> Subject

Merge two values. a is the “accumulated/existing” value, b is the “incoming” one.
Source§

impl PartialEq for Subject

Source§

fn eq(&self, other: &Subject) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Refinable for Subject

Source§

fn is_refinement_of(sup: &Subject, sub: &Subject) -> bool

Returns true if sub contains a subset of the information in sup.
Source§

impl StructuralPartialEq for Subject

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.