Skip to main content

WorldGraph

Struct WorldGraph 

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

The typed environmental digital twin (ADR-139). Wraps a petgraph StableDiGraph and exposes a domain API; stable WorldId → NodeIndex mapping survives node removal.

Implementations§

Source§

impl WorldGraph

Source

pub fn new(registration: GeoRegistration) -> Self

Create an empty graph registered to an installation origin.

Source

pub fn registration(&self) -> &GeoRegistration

Installation geo-registration (ADR-044).

Source

pub fn node_count(&self) -> usize

Number of live nodes.

Source

pub fn upsert_node(&mut self, node: WorldNode) -> WorldId

Insert or replace a node, returning its stable WorldId. If the node’s embedded id is UNASSIGNED, a fresh id is allocated; if it names an existing id, that node’s weight is replaced in place (upsert).

Source

pub fn add_edge( &mut self, from: WorldId, to: WorldId, edge: WorldEdge, ) -> Result<(), WorldGraphError>

Add a typed edge between two known nodes.

§Errors

WorldGraphError::UnknownNode if either endpoint is unknown.

Source

pub fn node(&self, id: WorldId) -> Option<&WorldNode>

Borrow a node by id.

Source

pub fn remove_node(&mut self, id: WorldId) -> Option<WorldNode>

Remove a node and its incident edges (e.g. a person leaves).

Source

pub fn neighbors(&self, id: WorldId) -> Vec<(WorldId, WorldEdge)>

Outgoing neighbours of a node with the connecting edge.

Source

pub fn room_for_area(&self, area_id: &str) -> Option<WorldId>

Resolve a HomeCore area_id to its Room node (entity linkage, ADR-127).

Source

pub fn observed_by(&self, sensor: WorldId) -> Vec<WorldId>

Observability chain: which nodes a sensor currently observes.

Source

pub fn contents_of(&self, container: WorldId) -> Vec<WorldId>

Location query: contents of a room/zone (incoming located_in edges).

Source

pub fn add_semantic_state( &mut self, statement: String, confidence: f32, valid_from_unix_ms: i64, provenance: SemanticProvenance, evidence_sources: &[WorldId], ) -> WorldId

Append-with-provenance: insert a SemanticState and wire DerivedFrom edges to its evidence sources (ADR-139 §2.3). Sources unknown to the graph are skipped (evidence may be raw frames not modelled as nodes).

Source

pub fn add_contradiction( &mut self, a: WorldId, b: WorldId, magnitude: f32, flag: String, ) -> Result<(), WorldGraphError>

Record a contradiction between two still-live beliefs (ADR-139 §2.3). Neither node is deleted — the disagreement stays queryable.

§Errors

WorldGraphError::UnknownNode if either node is unknown.

Source

pub fn apply_privacy_mode<F>( &mut self, mode: &str, action: &str, policy: F, ) -> PrivacyRollup
where F: Fn(&str, &str) -> bool,

Recompute PrivacyLimitedBy edges for the active mode (ADR-139 §2.4).

policy(modality_kind, node_kind) -> allowed decides, for each existing Observes edge, whether the sensor may still observe the target under mode. A matching PrivacyLimitedBy edge is appended recording the decision; denied pairs are rolled up.

Source

pub fn snapshot(&self) -> WorldGraphSnapshot

Snapshot the graph for persistence.

Source

pub fn to_json(&self) -> Result<Vec<u8>, WorldGraphError>

Serialize to deterministic JSON bytes (RVF payload).

§Errors

WorldGraphError::Serde on serialisation failure.

Source

pub fn from_json(bytes: &[u8]) -> Result<Self, WorldGraphError>

Reconstruct a graph from a snapshot’s JSON bytes.

§Errors

WorldGraphError::Serde on parse failure.

Trait Implementations§

Source§

impl Debug for WorldGraph

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more