1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Main Overnet functionality.

#![deny(missing_docs)]

mod coding;
mod future_help;
mod handle_info;
mod labels;
mod peer;
mod proxy;
mod router;
mod test_util;

// Export selected types from modules.
pub use coding::{decode_fidl, encode_fidl};
pub use future_help::log_errors;
pub use labels::{Endpoint, NodeId, NodeLinkId};
pub use router::{AscenddClientRouting, ListPeersContext, ListablePeer, Router};

pub use test_util::NodeIdGenerator;

/// Utility trait to trace a variable to the log.
#[allow(dead_code)]
pub(crate) trait Trace {
    /// Trace the caller - add `msg` as text to display, and `ctx` as some context
    /// for the system that caused this value to be traced.
    fn trace(self, msg: impl std::fmt::Display, ctx: impl std::fmt::Debug) -> Self
    where
        Self: Sized;

    fn maybe_trace(
        self,
        trace: bool,
        msg: impl std::fmt::Display,
        ctx: impl std::fmt::Debug,
    ) -> Self
    where
        Self: Sized,
    {
        if trace {
            self.trace(msg, ctx)
        } else {
            self
        }
    }
}

impl<X: std::fmt::Debug> Trace for X {
    fn trace(self, msg: impl std::fmt::Display, ctx: impl std::fmt::Debug) -> Self
    where
        Self: Sized,
    {
        tracing::info!("[{:?}] {}: {:?}", ctx, msg, self);
        self
    }
}