dynamo_runtime/traits.rs
1// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4pub mod events;
5
6use super::{DistributedRuntime, Runtime};
7/// A trait for objects that proivde access to the [Runtime]
8pub trait RuntimeProvider {
9 fn rt(&self) -> &Runtime;
10}
11
12/// A trait for objects that provide access to the [DistributedRuntime].
13pub trait DistributedRuntimeProvider {
14 fn drt(&self) -> &DistributedRuntime;
15}
16
17impl RuntimeProvider for DistributedRuntime {
18 fn rt(&self) -> &Runtime {
19 &self.runtime
20 }
21}
22
23// This implementation is required because:
24// 1. MetricsRegistry has a supertrait bound: `MetricsRegistry: Send + Sync + DistributedRuntimeProvider`
25// 2. DistributedRuntime implements MetricsRegistry (in distributed.rs)
26// 3. Therefore, DistributedRuntime must implement DistributedRuntimeProvider to satisfy the trait bound
27// 4. This enables DistributedRuntime to serve as both a provider (of itself) and a metrics registry
28impl DistributedRuntimeProvider for DistributedRuntime {
29 fn drt(&self) -> &DistributedRuntime {
30 self
31 }
32}