netstack3_trace/
id.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Types encoding trace point identifiers.
6
7use netstack3_sync::rc::ResourceToken;
8
9/// A resource identifier that can be used as an argument for trace events.
10pub struct TraceResourceId<'a> {
11    #[cfg_attr(not(target_os = "fuchsia"), allow(unused))]
12    token: ResourceToken<'a>,
13}
14
15impl<'a> TraceResourceId<'a> {
16    /// Creates a new resource id with the given value.
17    pub fn new(token: ResourceToken<'a>) -> Self {
18        Self { token }
19    }
20}
21
22#[cfg(target_os = "fuchsia")]
23impl<'a> fuchsia_trace::ArgValue for TraceResourceId<'a> {
24    fn of<'x>(key: &'x str, value: Self) -> fuchsia_trace::Arg<'x>
25    where
26        Self: 'x,
27    {
28        let Self { token } = value;
29        fuchsia_trace::ArgValue::of(key, token.export_value())
30    }
31}