overnet_core/
lib.rs

1// Copyright 2019 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//! Main Overnet functionality.
6
7#![deny(missing_docs)]
8
9mod coding;
10mod future_help;
11mod handle_info;
12mod labels;
13mod peer;
14mod proxy;
15mod router;
16mod test_util;
17
18// Export selected types from modules.
19pub use coding::{decode_fidl, encode_fidl};
20pub use future_help::log_errors;
21pub use labels::{Endpoint, NodeId, NodeLinkId};
22pub use proxy::set_proxy_drop_event_handler;
23pub use router::{AscenddClientRouting, ListPeersContext, ListablePeer, Router};
24
25pub use test_util::NodeIdGenerator;
26
27/// Utility trait to trace a variable to the log.
28#[allow(dead_code)]
29pub(crate) trait Trace {
30    /// Trace the caller - add `msg` as text to display, and `ctx` as some context
31    /// for the system that caused this value to be traced.
32    fn trace(self, msg: impl std::fmt::Display, ctx: impl std::fmt::Debug) -> Self
33    where
34        Self: Sized;
35
36    fn maybe_trace(
37        self,
38        trace: bool,
39        msg: impl std::fmt::Display,
40        ctx: impl std::fmt::Debug,
41    ) -> Self
42    where
43        Self: Sized,
44    {
45        if trace {
46            self.trace(msg, ctx)
47        } else {
48            self
49        }
50    }
51}
52
53impl<X: std::fmt::Debug> Trace for X {
54    fn trace(self, msg: impl std::fmt::Display, ctx: impl std::fmt::Debug) -> Self
55    where
56        Self: Sized,
57    {
58        log::info!("[{:?}] {}: {:?}", ctx, msg, self);
59        self
60    }
61}