MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / new

Method new

atomic-core/src/change/semantic_context.rs:80–100  ·  view source on GitHub ↗

Validate strictly ordered, one-to-one foreign-owner declarations. Invalid input is rejected, not normalized into a different declaration. # Examples ``` use atomic_core::change::{FileOps, semantic_context::{SemanticNameFrame, SemanticOwner}}; use atomic_core::{crdt::TrunkId, types::{Hash, NodeId}}; let frame = SemanticNameFrame::new(vec![SemanticOwner { authored_id: 91, owner: Hash::of(b"creatin

(owners: Vec<SemanticOwner>)

Source from the content-addressed store, hash-verified

78 /// # Ok::<(), atomic_core::change::semantic_context::SemanticContextError>(())
79 /// ```
80 pub fn new(owners: Vec<SemanticOwner>) -> Result<Self, SemanticContextError> {
81 if owners.iter().any(|entry| entry.authored_id == 0) {
82 return Err(SemanticContextError::RootName);
83 }
84 if owners.iter().any(|entry| entry.owner == Hash::NONE) {
85 return Err(SemanticContextError::RootOwner);
86 }
87 if owners
88 .windows(2)
89 .any(|pair| pair[0].authored_id >= pair[1].authored_id)
90 {
91 return Err(SemanticContextError::NonCanonicalNames);
92 }
93 let mut hashes = BTreeSet::new();
94 for entry in &owners {
95 if !hashes.insert(entry.owner) {
96 return Err(SemanticContextError::AliasedOwner(entry.owner));
97 }
98 }
99 Ok(Self { owners })
100 }
101
102 pub fn owners(&self) -> &[SemanticOwner] {
103 &self.owners

Callers

nothing calls this directly

Calls 2

iterMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected