pub struct Instance { /* private fields */ }Expand description
Owns an opaque instance identity and its mapped live handles.
Dropping this object does not remove graph structure from the destination. Cells begin with root parameters/private cells in local declaration order, then included private cells in inline expansion order. Bound child formals introduce no duplicate cell entries. Relationships follow inline expansion order and remain distinct even when their recipe belongs to a group. Occurrence records retain local mappings and immutable identity tokens, not template factories or recursively owned inclusion edges.
§Examples
See the module example.
Implementations§
Source§impl Instance
impl Instance
Sourcepub fn method_origins(
&self,
) -> impl Iterator<Item = (RelationshipId, usize, MethodOrigin)> + '_
pub fn method_origins( &self, ) -> impl Iterator<Item = (RelationshipId, usize, MethodOrigin)> + '_
Enumerates live methods and their authored origins in expansion order.
Tuple fields are relationship identity, compact method index, and authored origin. This avoids repeated linear searches when retaining all provenance.
- Complexity: O(r + m) time for r relationships and m surviving methods; O(1) additional space, excluding collected results.
§Examples
let template = adam_rs::TemplateBuilder::new().finish()?;
let instance = template.instantiate(&mut adam_rs::Sheet::new(), &[])?;
assert_eq!(instance.method_origins().count(), 0);Source§impl Instance
impl Instance
Sourcepub fn occurrences(&self) -> &[InstanceOccurrence]
pub fn occurrences(&self) -> &[InstanceOccurrence]
Borrows occurrences in depth-first inclusion order, beginning with the root.
Filtering by immediate parent yields children in authored inclusion order.
§Examples
See the occurrence example.
Sourcepub fn occurrence(&self, id: &OccurrenceId) -> Option<&InstanceOccurrence>
pub fn occurrence(&self, id: &OccurrenceId) -> Option<&InstanceOccurrence>
Returns an occurrence only if its identity belongs to this expansion.
§Examples
See the occurrence example.
Sourcepub fn cell(&self, occurrence: &OccurrenceId, slot: &CellSlot) -> Option<CellId>
pub fn cell(&self, occurrence: &OccurrenceId, slot: &CellSlot) -> Option<CellId>
Maps an owner-checked local cell to its live identity within an occurrence.
Returns None for a foreign occurrence or recipe handle. Bound formals
retain the caller’s cell identity.
§Examples
use adam_rs::{TemplateBuilder, Sheet};
let mut builder = TemplateBuilder::new();
let slot = builder.cell("private", || Ok(1i32))?;
let instance = builder.finish()?.instantiate(&mut Sheet::new(), &[])?;
assert_eq!(instance.cell(instance.occurrences()[0].id(), &slot), Some(instance.cells()[0]));Sourcepub fn relationship_group(
&self,
occurrence: &OccurrenceId,
slot: &RelationshipSlot,
) -> Option<&[RelationshipId]>
pub fn relationship_group( &self, occurrence: &OccurrenceId, slot: &RelationshipSlot, ) -> Option<&[RelationshipId]>
Borrows a local relationship’s live members, preserving separate runtime identities.
Inclusion groups contain their full transitive expansion, possibly empty.
Returns None for foreign occurrence or recipe handles.
§Examples
use adam_rs::{TemplateBuilder, Sheet};
use std::rc::Rc;
let child = Rc::new(TemplateBuilder::new().finish()?);
let mut builder = TemplateBuilder::new();
let included = builder.include(child, &[])?;
let instance = builder.finish()?.instantiate(&mut Sheet::new(), &[])?;
assert_eq!(instance.relationship_group(instance.occurrences()[0].id(),
&included.relationships()[0]), Some(&[][..]));Sourcepub fn method_origin(
&self,
relationship: RelationshipId,
live_method: usize,
) -> Option<MethodOrigin>
pub fn method_origin( &self, relationship: RelationshipId, live_method: usize, ) -> Option<MethodOrigin>
Returns the authored origin of a compact live method in this expansion.
Returns None if the relationship is absent or the method index is out of range.
- Complexity: O(r) time for r live relationships.
§Examples
use adam_rs::{TemplateBuilder, MethodRecipe, Method, Sheet};
let mut builder = TemplateBuilder::new();
let a = builder.cell("a", || Ok(1i32))?;
let b = builder.cell("b", || Ok(0i32))?;
builder.relationship(vec![MethodRecipe::new(&[a], &[b], |i, o| {
Ok(Method::from_fn_1_1(i[0], o[0], |x: &i32| Ok(*x)))
})?])?;
let instance = builder.finish()?.instantiate(&mut Sheet::new(), &[])?;
let origin = instance.method_origin(instance.relationships()[0], 0).unwrap();
assert_eq!(origin.authored_index, 0);Source§impl Instance
impl Instance
Sourcepub fn relationships(&self) -> &[RelationshipId]
pub fn relationships(&self) -> &[RelationshipId]
Sourcepub fn cells(&self) -> &[CellId]
pub fn cells(&self) -> &[CellId]
Borrows all mapped cells, including unchanged parameter identities.
§Examples
See the module example.