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//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16pub mod events;
17
18use super::{DistributedRuntime, Runtime};
19/// A trait for objects that proivde access to the [Runtime]
20pub trait RuntimeProvider {
21 fn rt(&self) -> &Runtime;
22}
23
24/// A trait for objects that provide access to the [DistributedRuntime].
25pub trait DistributedRuntimeProvider {
26 fn drt(&self) -> &DistributedRuntime;
27}
28
29impl RuntimeProvider for DistributedRuntime {
30 fn rt(&self) -> &Runtime {
31 &self.runtime
32 }
33}
34
35// This implementation is required because:
36// 1. MetricsRegistry has a supertrait bound: `MetricsRegistry: Send + Sync + DistributedRuntimeProvider`
37// 2. DistributedRuntime implements MetricsRegistry (in distributed.rs)
38// 3. Therefore, DistributedRuntime must implement DistributedRuntimeProvider to satisfy the trait bound
39// 4. This enables DistributedRuntime to serve as both a provider (of itself) and a metrics registry
40impl DistributedRuntimeProvider for DistributedRuntime {
41 fn drt(&self) -> &DistributedRuntime {
42 self
43 }
44}