1
//! Implement synchronous views of circuit internals.
2

            
3
use crate::circuit::circhop::CircHopOutbound;
4

            
5
/// A view of a circuit hop's internals, usable in a synchronous callback.
6
//
7
// TODO: I would rather have this type have a mutable reference to the reactor itself,
8
// rather than just an immutable reference to a piece of it.
9
// But that creates borrow-checker problems, so instead for now,
10
// we only hold references to the pieces we need.
11
//
12
// If we need to hold more info in the future,
13
// we'll need to decide whether to create additional types for the more complex variants,
14
// or whether to try to stuff everything inside this type.
15
pub struct CircHopSyncView<'a> {
16
    /// The hop of the circuit used to implement this view.
17
    pub(super) hop: &'a CircHopOutbound,
18
}
19

            
20
impl<'a> CircHopSyncView<'a> {
21
    /// Construct a new view of a circuit hop, given a mutable reference to its outbound hop view.
22
36
    pub(crate) fn new(hop: &'a CircHopOutbound) -> Self {
23
36
        Self { hop }
24
36
    }
25

            
26
    /// Return the number of streams currently open on this circuit hop.
27
    pub fn n_open_streams(&self) -> usize {
28
        self.hop.n_open_streams()
29
    }
30
}