Skip to main content

Instance

Struct Instance 

Source
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

Source

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

Source

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.

Source

pub fn occurrence(&self, id: &OccurrenceId) -> Option<&InstanceOccurrence>

Returns an occurrence only if its identity belongs to this expansion.

§Examples

See the occurrence example.

Source

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]));
Source

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(&[][..]));
Source

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

Source

pub fn relationships(&self) -> &[RelationshipId]

Borrows live relationship handles in inline declaration order.

§Examples

See the module example.

Source

pub fn cells(&self) -> &[CellId]

Borrows all mapped cells, including unchanged parameter identities.

§Examples

See the module example.

Trait Implementations§

Source§

impl Debug for Instance

Source§

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

Formats the value using the given formatter. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.