Skip to content

Commit 153afda

Browse files
authored
refactor(common): remove uid-mux dependency (#368)
1 parent b8b8884 commit 153afda

11 files changed

Lines changed: 226 additions & 183 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ bytemuck = { version = "1.13", features = ["derive"] }
119119
zerocopy = "0.8"
120120
serio = { version = "0.2" }
121121

122-
# io
123-
uid-mux = { version = "0.2" }
124-
125122
# testing
126123
rstest = "0.12"
127124
pretty_assertions = "1"

crates/common/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ default = []
88
executor = []
99
sync = ["tokio/sync"]
1010
future = []
11-
test-utils = ["uid-mux/test-utils", "tokio/io-util", "tokio-util/compat"]
11+
test-utils = ["tokio/io-util", "tokio-util/compat"]
1212
ideal = ["tokio/sync"]
1313

1414
[dependencies]
@@ -18,7 +18,6 @@ bytes = { workspace = true }
1818
pin-project-lite.workspace = true
1919
thiserror.workspace = true
2020
serio.workspace = true
21-
uid-mux = { workspace = true }
2221
serde = { workspace = true, features = ["derive"] }
2322
pollster.workspace = true
2423
cfg-if.workspace = true
@@ -34,7 +33,6 @@ tokio = { workspace = true, features = [
3433
"net",
3534
] }
3635
tokio-util = { workspace = true, features = ["compat"] }
37-
uid-mux = { workspace = true, features = ["test-utils"] }
3836
tracing-subscriber = { workspace = true, features = ["fmt"] }
3937
criterion = { workspace = true, features = ["async_tokio"] }
4038
rstest = { workspace = true }

crates/common/src/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Context {
118118
match &mut self.mode {
119119
Mode::St => Ok(st::map(self, items, f).await),
120120
Mode::Mt { threads } => {
121-
let threads = threads.get(threads.concurrency()).await?;
121+
let threads = threads.get(threads.concurrency())?;
122122
mt::map(threads, items, f, weight).await
123123
}
124124
}
@@ -138,7 +138,7 @@ impl Context {
138138
match &mut self.mode {
139139
Mode::St => Ok(st::join(self, a, b).await),
140140
Mode::Mt { threads } => {
141-
let threads = threads.get(2).await?;
141+
let threads = threads.get(2)?;
142142
mt::join(threads, a, b).await
143143
}
144144
}
@@ -167,7 +167,7 @@ impl Context {
167167
match &mut self.mode {
168168
Mode::St => Ok(st::try_join(self, a, b).await),
169169
Mode::Mt { threads } => {
170-
let threads = threads.get(2).await?;
170+
let threads = threads.get(2)?;
171171
mt::try_join(threads, a, b).await
172172
}
173173
}
@@ -192,7 +192,7 @@ impl Context {
192192
match &mut self.mode {
193193
Mode::St => Ok(st::try_join3(self, a, b, c).await),
194194
Mode::Mt { threads } => {
195-
let threads = threads.get(3).await?;
195+
let threads = threads.get(3)?;
196196
mt::try_join3(threads, a, b, c).await
197197
}
198198
}
@@ -220,7 +220,7 @@ impl Context {
220220
match &mut self.mode {
221221
Mode::St => Ok(st::try_join4(self, a, b, c, d).await),
222222
Mode::Mt { threads } => {
223-
let threads = threads.get(4).await?;
223+
let threads = threads.get(4)?;
224224
mt::try_join4(threads, a, b, c, d).await
225225
}
226226
}

crates/common/src/context/mt.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ impl Multithread {
4141
ContextError::new(ErrorKind::Thread, "thread ID overflow".to_string())
4242
})?;
4343

44-
let io_fut = { self.builder.lock().unwrap().mux.open(id.clone()) };
45-
46-
let io = io_fut
47-
.await
44+
let io = self
45+
.builder
46+
.lock()
47+
.unwrap()
48+
.mux
49+
.open(id.clone())
4850
.map_err(|e| ContextError::new(ErrorKind::Mux, e))?;
4951

5052
let ctx =
@@ -60,15 +62,16 @@ pub(crate) struct ThreadBuilder {
6062
}
6163

6264
impl ThreadBuilder {
63-
async fn spawn(
65+
fn spawn(
6466
this: Arc<Mutex<Self>>,
6567
id: ThreadId,
6668
config: Arc<MtConfig>,
6769
) -> Result<Handle, ContextError> {
68-
let io_fut = { this.lock().unwrap().mux.open(id.clone()) };
69-
70-
let io = io_fut
71-
.await
70+
let io = this
71+
.lock()
72+
.unwrap()
73+
.mux
74+
.open(id.clone())
7275
.map_err(|e| ContextError::new(ErrorKind::Mux, e))?;
7376

7477
let ctx = Context::new_multi_threaded(id.clone(), io, config, this.clone());
@@ -115,7 +118,7 @@ impl Threads {
115118
self.config.concurrency
116119
}
117120

118-
pub(crate) async fn get(&mut self, count: usize) -> Result<&[Handle], ContextError> {
121+
pub(crate) fn get(&mut self, count: usize) -> Result<&[Handle], ContextError> {
119122
if count > self.config.concurrency {
120123
return Err(ContextError::new(
121124
ErrorKind::Thread,
@@ -128,8 +131,7 @@ impl Threads {
128131
ContextError::new(ErrorKind::Thread, "thread ID overflow".to_string())
129132
})?;
130133

131-
let child =
132-
ThreadBuilder::spawn(self.builder.clone(), id, self.config.clone()).await?;
134+
let child = ThreadBuilder::spawn(self.builder.clone(), id, self.config.clone())?;
133135
self.children.push(child);
134136
}
135137
}

crates/common/src/context/mt/builder.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::sync::{Arc, Mutex};
22

3-
use uid_mux::UidMux;
4-
53
use crate::{
64
ThreadId,
75
context::{
@@ -73,18 +71,8 @@ impl<S> MultithreadBuilder<S> {
7371
}
7472

7573
/// Sets the multiplexer.
76-
pub fn mux<M>(mut self, mux: M) -> Self
77-
where
78-
M: UidMux<ThreadId> + Clone + Send + Sync + 'static,
79-
<M as UidMux<ThreadId>>::Error: std::error::Error + Send + Sync + 'static,
80-
{
81-
self.mux = Some(Box::new(mux));
82-
self
83-
}
84-
85-
#[allow(dead_code)]
86-
pub(crate) fn mux_internal(mut self, mux: Box<dyn Mux + Send>) -> Self {
87-
self.mux = Some(mux);
74+
pub fn mux<M: Into<Box<dyn Mux + Send>>>(mut self, mux: M) -> Self {
75+
self.mux = Some(mux.into());
8876
self
8977
}
9078

crates/common/src/context/test/helpers.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Basic test context helpers.
22
3+
use crate::mux::test_framed_mux;
34
use futures::{AsyncRead, AsyncWrite};
45
use serio::channel::duplex;
5-
use uid_mux::test_utils::test_framed_mux;
66

77
use crate::{
88
context::{Context, Multithread, SpawnError},
@@ -41,8 +41,8 @@ pub fn test_mt_context(io_buffer: usize) -> (Multithread, Multithread) {
4141
let mux_1: Box<dyn Mux + Send> = Box::new(mux_1);
4242

4343
(
44-
Multithread::builder().mux_internal(mux_0).build().unwrap(),
45-
Multithread::builder().mux_internal(mux_1).build().unwrap(),
44+
Multithread::builder().mux(mux_0).build().unwrap(),
45+
Multithread::builder().mux(mux_1).build().unwrap(),
4646
)
4747
}
4848

@@ -62,12 +62,12 @@ where
6262
(
6363
Multithread::builder()
6464
.spawn_handler(spawn.clone())
65-
.mux_internal(mux_0)
65+
.mux(mux_0)
6666
.build()
6767
.unwrap(),
6868
Multithread::builder()
6969
.spawn_handler(spawn)
70-
.mux_internal(mux_1)
70+
.mux(mux_1)
7171
.build()
7272
.unwrap(),
7373
)
@@ -95,13 +95,13 @@ where
9595
Multithread::builder()
9696
.concurrency(concurrency)
9797
.spawn_handler(spawn.clone())
98-
.mux_internal(mux_0)
98+
.mux(mux_0)
9999
.build()
100100
.unwrap(),
101101
Multithread::builder()
102102
.concurrency(concurrency)
103103
.spawn_handler(spawn)
104-
.mux_internal(mux_1)
104+
.mux(mux_1)
105105
.build()
106106
.unwrap(),
107107
)

0 commit comments

Comments
 (0)