Reference Target
The Reference Target semantic module constrains an entity reference to a
specific entity type. A targeted ref links one entity to another entity of a
declared type. Here, the task’s started event records which Worker runs it.
YAML model
quent: alpha
model: references
entities:
Worker:
events:
registered: {}
Task:
events:
started:
attributes:
worker: { ref: Worker }
ended: {}
Instrumentation API
An entity handle produces a typed reference with as_entity_ref. The generated
started method only accepts a reference targeting Worker.
// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#[allow(unused)]
mod instrumentation {
include!(concat!(env!("OUT_DIR"), "/references.rs"));
}
use instrumentation::{Context, Noop, References, Task, Worker};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let context = Context::<References>::try_new(Noop)?;
let mut worker = context.observer::<Worker>().handle();
worker.registered()?;
let mut task = context.observer::<Task>().handle();
// A `Task` reference has the wrong target type, so this would not compile:
// let other_task = context.observer::<Task>().handle();
// task.started(other_task.as_entity_ref())?;
task.started(worker.as_entity_ref())?;
task.ended()?;
Ok(())
}
Key point
An entity reference identifies a specific entity and preserves its type.