Skip to content

Commit a90be6f

Browse files
author
Mikhail Vasilyev
committed
reorg and rename
1 parent 9db1fd9 commit a90be6f

12 files changed

Lines changed: 48 additions & 34 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "local_async_utils"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Mikhail Vasilyev"]
66
description = "Utilities for single-threaded async programming"

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
pub mod local_sync;
21
pub mod sealed;
32
pub mod shared;
43
pub mod stopwatch;
4+
pub mod sync;
55
pub mod time;
6+
7+
pub mod prelude {
8+
pub use crate::sealed;
9+
pub use crate::shared::*;
10+
pub use crate::stopwatch::Stopwatch;
11+
pub use crate::sync::channel as local_channel;
12+
pub use crate::sync::condvar as local_condvar;
13+
pub use crate::sync::oneshot as local_oneshot;
14+
pub use crate::sync::semaphore as local_semaphore;
15+
pub use crate::{
16+
debug_stopwatch, error_stopwatch, info_stopwatch, trace_stopwatch, warn_stopwatch,
17+
};
18+
pub use crate::{millisec, min, sec};
19+
}

src/local_sync/mod.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::shared::Shared;
1+
use super::Shared;
22
use std::cell::RefCell;
33
use std::rc::Rc;
44

src/shared/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub mod local_shared;
2+
pub mod projected_shared;
3+
4+
pub use local_shared::LocalShared;
5+
pub use projected_shared::ProjectedShared;
6+
7+
pub trait Shared: Clone {
8+
type Target;
9+
10+
fn with<R, F>(&mut self, f: F) -> R
11+
where
12+
F: FnOnce(&mut Self::Target) -> R;
13+
14+
fn project<To, Proj>(&self, f: Proj) -> ProjectedShared<Self, Proj>
15+
where
16+
Proj: Fn(&mut Self::Target) -> &mut To + Clone,
17+
{
18+
ProjectedShared {
19+
inner: self.clone(),
20+
proj_fn: f,
21+
}
22+
}
23+
}

src/shared.rs renamed to src/shared/projected_shared.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
pub trait Shared: Clone {
2-
type Target;
3-
4-
fn with<R, F>(&mut self, f: F) -> R
5-
where
6-
F: FnOnce(&mut Self::Target) -> R;
7-
8-
fn project<To, Proj>(&self, f: Proj) -> ProjectedShared<Self, Proj>
9-
where
10-
Proj: Fn(&mut Self::Target) -> &mut To + Clone,
11-
{
12-
ProjectedShared {
13-
inner: self.clone(),
14-
proj_fn: f,
15-
}
16-
}
17-
}
1+
use super::Shared;
182

193
pub struct ProjectedShared<T, F> {
20-
inner: T,
21-
proj_fn: F,
4+
pub(super) inner: T,
5+
pub(super) proj_fn: F,
226
}
237

248
impl<From, To, Inner, Proj> Shared for ProjectedShared<Inner, Proj>

src/sync/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod channel;
2+
pub mod condvar;
3+
pub mod oneshot;
4+
pub mod semaphore;
5+
mod shared_state;

0 commit comments

Comments
 (0)