Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

Graph container — the one Core-free namespace + mount-tree handle (canonical §3, D246).

Clone is a cheap Rc bump; a subgraph (from mount*/ancestors) is just a Graph into a child level. Intentionally !Send + !Sync (D246/S2c single-owner): no Core, no borrow — captured into owner-side sinks on the one thread that owns the Core. Pass the embedder’s &Core (e.g. owned.core()) into every Core-touching method.

Implementations§

Source§

impl Graph

Source

pub fn new(name: impl Into<String>) -> Self

Construct a named, empty root graph. D246: the graph is Core-free — the embedder owns the Core (see graphrefly_core::OwnedCore) and passes &Core into Core-touching ops.

Source

pub fn is_valid_name(name: &str) -> bool

Whether name is a legal local node/subgraph name.

Source

pub fn name(&self) -> String

The graph’s name as set at construction (or via mount).

Source

pub fn subscribe_namespace_change(&self, sink: Arc<dyn Fn(&Core)>) -> u64

Subscribe to namespace changes (add, remove, mount, unmount, destroy). The sink fires AFTER the inner lock is dropped, with the owner’s &Core. Returns a subscription id.

Source

pub fn unsubscribe_namespace_change(&self, id: u64)

Unsubscribe a namespace-change sink by id (owner-invoked, D246 rule 3 — no RAII below the binding).

Source

pub fn describe(&self, core: &Core) -> GraphDescribeOutput

Snapshot the graph’s topology + lifecycle state (JSON form). value fields are raw u64 handles.

Source

pub fn describe_with_debug( &self, core: &Core, debug: &dyn DebugBindingBoundary, ) -> GraphDescribeOutput

Self::describe with each value rendered via debug.

Source

pub fn describe_reactive( &self, core: &Core, sink: &DescribeSink, ) -> ReactiveDescribeHandle

Subscribe to live topology snapshots (canonical §3.6.1 reactive: true). Push-on-subscribe + re-fires on namespace changes and set_deps. D246 rule 3: returns an id-bearing handle with an explicit owner-invoked ReactiveDescribeHandle::detach — no RAII Drop.

Source

pub fn observe(&self, path: &str) -> GraphObserveOne

Tap a single node’s downstream message stream. Pure-namespace resolution; pass &Core to the returned handle’s subscribe.

Source

pub fn observe_all(&self) -> GraphObserveAll

Tap every named node in this graph (snapshot at subscribe()).

Source

pub fn observe_all_reactive(&self) -> GraphObserveAllReactive

Tap every named node AND auto-subscribe late-added nodes.

Source

pub fn fire_namespace_change(&self, core: &Core)

Fire all namespace-change sinks owner-side (D246 rule 2 — caller holds &Core).

Source

pub fn add( &self, core: &Core, node_id: NodeId, name: impl Into<String>, ) -> Result<NodeId, NameError>

Register an existing node_id under name in this graph’s namespace.

§Errors

See NameError.

Source

pub fn node(&self, path: &str) -> NodeId

Resolve a path to a NodeId. Panics if missing.

Source

pub fn try_resolve(&self, path: &str) -> Option<NodeId>

Non-panicking Self::node.

Source

pub fn try_resolve_checked( &self, path: &str, ) -> Result<Option<NodeId>, PathError>

Path resolution with typed errors (pure-namespace; never touches Core).

§Errors

See PathError.

Source

pub fn name_of(&self, node_id: NodeId) -> Option<String>

Reverse lookup: the local name for a node_id.

Source

pub fn node_count(&self) -> usize

Number of named nodes in this graph.

Source

pub fn node_names(&self) -> Vec<String>

Snapshot of local node names in insertion order.

Source

pub fn child_names(&self) -> Vec<String>

Snapshot of mounted child names in insertion order.

Source

pub fn is_destroyed(&self) -> bool

Returns true after Self::destroy has been called.

Source

pub fn state( &self, core: &Core, name: impl Into<String>, initial: Option<HandleId>, ) -> Result<NodeId, NameError>

Register a state node under name.

§Errors

See NameError.

Source

pub fn derived( &self, core: &Core, name: impl Into<String>, deps: &[NodeId], fn_id: FnId, equals: EqualsMode, ) -> Result<NodeId, NameError>

Register a static-derived node (fn fires on every dep change).

§Errors

See NameError.

Source

pub fn dynamic( &self, core: &Core, name: impl Into<String>, deps: &[NodeId], fn_id: FnId, equals: EqualsMode, ) -> Result<NodeId, NameError>

Register a dynamic-derived node (fn declares read dep indices).

§Errors

See NameError.

Source

pub fn set(&self, core: &Core, name: &str, handle: HandleId)

Emit a value on a named state node.

Source

pub fn get(&self, core: &Core, name: &str) -> HandleId

Read the cached value of a named node.

Source

pub fn invalidate_by_name(&self, core: &Core, name: &str)

Clear the cache of a named node and cascade [INVALIDATE].

Source

pub fn complete_by_name(&self, core: &Core, name: &str)

Mark a named node terminal with COMPLETE.

Source

pub fn error_by_name(&self, core: &Core, name: &str, error_handle: HandleId)

Mark a named node terminal with ERROR.

Source

pub fn remove( &self, core: &Core, name: &str, ) -> Result<GraphRemoveAudit, RemoveError>

Remove a named node OR mounted subgraph (R3.2.3 / R3.7.3 ordering — namespace cleared AFTER the TEARDOWN cascade).

§Errors

See RemoveError.

Source

pub fn edges(&self, core: &Core, recursive: bool) -> Vec<(String, String)>

Derive [from, to] edge name pairs. recursive qualifies names across the mount tree with ::.

Source

pub fn subscribe( &self, core: &Core, node_id: NodeId, sink: Sink, ) -> SubscriptionId

Subscribe a sink. Returns a SubscriptionId; pass it back to Self::unsubscribe (owner-invoked, synchronous — D246 rule 3; no RAII below the binding).

Source

pub fn unsubscribe(&self, core: &Core, node_id: NodeId, sub_id: SubscriptionId)

Detach a sink previously registered via Self::subscribe.

Source

pub fn unsubscribe_topology(&self, core: &Core, id: TopologySubscriptionId)

Detach a Core topology subscription by id.

Source

pub fn emit(&self, core: &Core, node_id: NodeId, new_handle: HandleId)

Emit a value on a state node.

Source

pub fn cache_of(&self, core: &Core, node_id: NodeId) -> HandleId

Read a node’s current cache.

Source

pub fn has_fired_once(&self, core: &Core, node_id: NodeId) -> bool

Whether the node’s fn has fired at least once.

Source

pub fn complete(&self, core: &Core, node_id: NodeId)

Mark the node terminal with COMPLETE.

Source

pub fn error(&self, core: &Core, node_id: NodeId, error_handle: HandleId)

Mark the node terminal with ERROR.

Source

pub fn teardown(&self, core: &Core, node_id: NodeId)

Tear the node down (R2.6.4).

Source

pub fn invalidate(&self, core: &Core, node_id: NodeId)

Clear the node’s cache and cascade [INVALIDATE].

Source

pub fn pause( &self, core: &Core, node_id: NodeId, lock_id: LockId, ) -> Result<(), PauseError>

Acquire a pause lock.

§Errors

See PauseError.

Source

pub fn resume( &self, core: &Core, node_id: NodeId, lock_id: LockId, ) -> Result<Option<ResumeReport>, PauseError>

Release a pause lock.

§Errors

See PauseError.

Source

pub fn alloc_lock_id(&self, core: &Core) -> LockId

Allocate a fresh LockId.

Source

pub fn set_deps( &self, core: &Core, n: NodeId, new_deps: &[NodeId], ) -> Result<(), SetDepsError>

Atomically rewire a node’s deps.

§Errors

See SetDepsError.

§Hazards

Re-entrant set_deps from inside the firing node’s own fn corrupts Dynamic tracked indices (D1 in ~/src/graphrefly-rs/docs/porting-deferred.md). Acceptable v1: most callers are external orchestrators, not the firing node.

Source

pub fn set_resubscribable( &self, core: &Core, node_id: NodeId, resubscribable: bool, )

Mark the node as resubscribable (R2.2.7).

Source

pub fn add_meta_companion(&self, core: &Core, parent: NodeId, companion: NodeId)

Attach companion as a meta companion of parent (R1.3.9.d).

Source

pub fn batch<F: FnOnce()>(&self, core: &Core, f: F)

Coalesce multiple emissions into a single wave.

Source

pub fn signal(&self, core: &Core, kind: SignalKind)

General broadcast (canonical R3.7.1).

Source

pub fn signal_invalidate(&self, core: &Core)

Broadcast [INVALIDATE] across this graph + mount tree (meta-companion filtered per R3.7.2; Graph locks dropped before any Core::invalidate). Idempotent on a destroyed graph.

Source

pub fn destroy(&self, core: &Core)

Tear down every named node + recursively into mounted children, then clear namespace + mount-tree state. R3.7.3 ordering (children-first, then own teardown, then clear, then fire ns-change) preserved verbatim.

Source

pub fn mount( &self, core: &Core, name: impl Into<String>, child: &Graph, ) -> Result<Graph, MountError>

Embed an existing child subgraph under name. Fires ns-change sinks owner-side (P3) — hence &Core (D246 rule 2).

§Errors

See MountError.

Source

pub fn mount_new( &self, core: &Core, name: impl Into<String>, ) -> Result<Graph, MountError>

Create an empty subgraph (shares the embedder’s one Core).

§Errors

See MountError.

Source

pub fn mount_with<F: FnOnce(&Graph)>( &self, core: &Core, name: impl Into<String>, builder: F, ) -> Result<Graph, MountError>

Builder pattern: create an empty subgraph, run builder, return it.

§Errors

See MountError.

Source

pub fn unmount( &self, core: &Core, name: &str, ) -> Result<GraphRemoveAudit, MountError>

Detach a previously-mounted subgraph (TEARDOWN cascade).

§Errors

See MountError.

Source

pub fn ancestors(&self, include_self: bool) -> Vec<Graph>

Parent chain (root last). include_self = true prepends this graph.

Source§

impl Graph

Source

pub fn snapshot(&self, core: &Core) -> GraphPersistSnapshot

Serialize this graph’s state into a portable snapshot.

Source

pub fn snapshot_full(&self, core: &dyn CoreFull) -> GraphPersistSnapshot

Self::snapshot over the one object-safe facade (D246 rule 5) — for the storage in-wave MailboxOp::Defer(|cf: &dyn CoreFull|) path, which only has a &dyn CoreFull (not a concrete &Core). Read-only; serialize_handle delegates to the binding.

Source

pub fn restore( &self, core: &Core, snapshot: &GraphPersistSnapshot, ) -> Result<(), SnapshotError>

Restore state from a snapshot into this existing graph.

§Errors

NameMismatch if names differ; UnknownNode/UnknownSubgraph for snapshot entries absent from the graph.

Source

pub fn from_snapshot( core: &Core, snapshot: &GraphPersistSnapshot, builder: Option<SnapshotBuilder>, factories: Option<IndexMap<String, NodeFactory>>, ) -> Result<Self, SnapshotError>

Reconstruct a graph from a snapshot. Builder mode (builder = Some): build topology then restore() values. Auto-hydration (builder = None): reconstruct topology + state from the snapshot via factories (state nodes need none).

D246: the embedder owns the Core (see graphrefly_core::OwnedCore) and passes it in; the binding is core.binding_ptr().

§Errors

UnresolvableDeps if auto-hydration can’t resolve a node’s deps; MissingFactory for a non-state node type with no factory.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl !Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl !UnwindSafe for Graph

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> Same for T

Source§

type Output = T

Should always be Self
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, 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.