Skip to content

Commit 85ac12e

Browse files
committed
refactor: Remove some pub(super)
1 parent e4ba54f commit 85ac12e

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

src/global.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ impl Global {
6262
None
6363
};
6464

65-
Ok(InputSourceHandle {
66-
input_source: self.0.write().await.register_input_source(name, priority),
67-
global: self.clone(),
68-
})
65+
Ok(InputSourceHandle::new(
66+
self.0.write().await.register_input_source(name, priority),
67+
self.clone(),
68+
))
6969
}
7070

7171
pub async fn register_muxed_source(
7272
&self,
7373
name: InputSourceName,
7474
) -> Result<InputSourceHandle<MuxedMessage>, InputSourceError> {
75-
Ok(InputSourceHandle {
76-
input_source: self.0.write().await.register_muxed_source(name),
77-
global: self.clone(),
78-
})
75+
Ok(InputSourceHandle::new(
76+
self.0.write().await.register_muxed_source(name),
77+
self.clone(),
78+
))
7979
}
8080

8181
pub async fn subscribe_input(&self) -> broadcast::Receiver<InputMessage> {
@@ -130,12 +130,7 @@ impl GlobalData {
130130
let id = self.next_input_source_id;
131131
self.next_input_source_id += 1;
132132

133-
let input_source = Arc::new(InputSource {
134-
id,
135-
name,
136-
priority,
137-
tx: self.input_tx.clone(),
138-
});
133+
let input_source = Arc::new(InputSource::new(id, name, priority, self.input_tx.clone()));
139134

140135
info!("registered new input source {}", *input_source);
141136

@@ -145,7 +140,7 @@ impl GlobalData {
145140
}
146141

147142
fn unregister_input_source(&mut self, source: &InputSource<InputMessage>) {
148-
if let Some(is) = self.input_sources.remove(&source.id) {
143+
if let Some(is) = self.input_sources.remove(&source.id()) {
149144
info!("unregistered input source {}", *is);
150145
}
151146
}
@@ -154,12 +149,7 @@ impl GlobalData {
154149
let id = self.next_muxed_source_id;
155150
self.next_muxed_source_id += 1;
156151

157-
let input_source = Arc::new(InputSource {
158-
id,
159-
name,
160-
priority: None,
161-
tx: self.muxed_tx.clone(),
162-
});
152+
let input_source = Arc::new(InputSource::new(id, name, None, self.muxed_tx.clone()));
163153

164154
info!("registered new muxed source {}", *input_source);
165155

@@ -169,7 +159,7 @@ impl GlobalData {
169159
}
170160

171161
fn unregister_muxed_source(&mut self, source: &InputSource<MuxedMessage>) {
172-
if let Some(is) = self.muxed_sources.remove(&source.id) {
162+
if let Some(is) = self.muxed_sources.remove(&source.id()) {
173163
info!("unregistered muxed source {}", *is);
174164
}
175165
}

src/global/input_source.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ use super::{Global, InputSourceName, Message};
99
#[derive(Display)]
1010
#[display("`{name}` (id = {id}, priority = {priority:?})")]
1111
pub struct InputSource<T: Message> {
12-
pub(super) id: usize,
13-
pub(super) name: InputSourceName,
14-
pub(super) priority: Option<i32>,
15-
pub(super) tx: broadcast::Sender<T>,
12+
id: usize,
13+
name: InputSourceName,
14+
priority: Option<i32>,
15+
tx: broadcast::Sender<T>,
1616
}
1717

1818
impl<T: Message> InputSource<T> {
19+
pub fn new(
20+
id: usize,
21+
name: InputSourceName,
22+
priority: Option<i32>,
23+
tx: broadcast::Sender<T>,
24+
) -> Self {
25+
Self {
26+
id,
27+
name,
28+
priority,
29+
tx,
30+
}
31+
}
32+
1933
pub fn id(&self) -> usize {
2034
self.id
2135
}
@@ -30,8 +44,17 @@ impl<T: Message> InputSource<T> {
3044
}
3145

3246
pub struct InputSourceHandle<T: Message> {
33-
pub(super) input_source: Arc<InputSource<T>>,
34-
pub(super) global: Global,
47+
input_source: Arc<InputSource<T>>,
48+
global: Global,
49+
}
50+
51+
impl<T: Message> InputSourceHandle<T> {
52+
pub fn new(input_source: Arc<InputSource<T>>, global: Global) -> Self {
53+
Self {
54+
input_source,
55+
global,
56+
}
57+
}
3558
}
3659

3760
impl<T: Message> std::ops::Deref for InputSourceHandle<T> {

0 commit comments

Comments
 (0)