Skip to content

Commit c36bd5b

Browse files
committed
add prelude. make tests compile but crash
1 parent ef4b86c commit c36bd5b

File tree

7 files changed

+46
-12
lines changed

7 files changed

+46
-12
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ authors = [
1515
[features]
1616

1717
[dependencies]
18+
async-channel.workspace = true
1819
futures-core.workspace = true
1920
http.workspace = true
2021
pin-project-lite.workspace = true
@@ -24,6 +25,7 @@ wstd-macro.workspace = true
2425

2526
[dev-dependencies]
2627
anyhow.workspace = true
28+
futures-lite.workspace = true
2729
serde_json.workspace = true
2830
test-programs-artifacts.workspace = true
2931
wasmtime.workspace = true
@@ -47,8 +49,10 @@ repository = "https://github.com/yoshuawuyts/wstd"
4749

4850
[workspace.dependencies]
4951
anyhow = "1"
52+
async-channel = "1.6.1"
5053
cargo_metadata = "0.18.1"
5154
futures-core = "0.3.19"
55+
futures-lite = "1.12.0"
5256
heck = "0.5"
5357
http = "1.1"
5458
pin-project-lite = "0.2.8"

src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#![allow(async_fn_in_trait)]
2+
#![warn(future_incompatible, unreachable_pub)]
3+
//#![deny(missing_debug_implementations)]
4+
//#![warn(missing_docs)]
5+
//#![forbid(rustdoc::missing_doc_code_examples)]
26

37
//! An async standard library for Wasm Components and WASI 0.2
48
//!
@@ -53,3 +57,28 @@ pub mod runtime;
5357
pub mod time;
5458

5559
pub use wstd_macro::attr_macro_main as main;
60+
61+
pub mod prelude {
62+
pub use crate::http::Body as _;
63+
pub use crate::io::AsyncRead as _;
64+
pub use crate::io::AsyncWrite as _;
65+
pub use crate::time::future::FutureExt as _;
66+
pub use crate::time::future::Timer as _;
67+
pub use crate::time::stream::IntoStream as _;
68+
pub use crate::time::stream::StreamExt as _;
69+
pub use std::future::IntoFuture as _;
70+
}
71+
72+
/// An async multi-producer multi-consumer channel.
73+
pub mod channel {
74+
/// Suspend or resume execution of a future.
75+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
76+
pub enum Parker {
77+
/// Put the future into a suspended state.
78+
Park,
79+
/// Put the future into an active state.
80+
Unpark,
81+
}
82+
#[doc(inline)]
83+
pub use async_channel::*;
84+
}

src/time/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub fn interval(duration: Duration) -> Interval {
3838
/// An async iterator representing notifications at fixed interval.
3939
///
4040
/// See the [`interval`] function for more.
41+
#[derive(Debug)]
4142
pub struct Interval {
4243
duration: Duration,
4344
}

src/time/stream/buffer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ mod test {
107107

108108
#[test]
109109
fn buffer_all_values() {
110-
async_io::block_on(async {
110+
crate::runtime::block_on(async {
111111
let interval = Duration::from_millis(5);
112112
let buffer = Duration::from_millis(20);
113113

114114
let mut counter = 0;
115-
crate::stream::interval(interval)
115+
crate::time::stream::interval(interval)
116116
.take(10)
117117
.buffer(buffer)
118118
.for_each(|buf| counter += buf.len())
@@ -124,12 +124,12 @@ mod test {
124124

125125
#[test]
126126
fn no_debounces_hit() {
127-
async_io::block_on(async {
127+
crate::runtime::block_on(async {
128128
let interval = Duration::from_millis(20);
129129
let buffer = Duration::from_millis(10);
130130

131131
let mut counter = 0;
132-
crate::stream::interval(interval)
132+
crate::time::stream::interval(interval)
133133
.take(10)
134134
.buffer(buffer)
135135
.for_each(|buf| counter += buf.len())

src/time/stream/debounce.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ mod test {
111111

112112
#[test]
113113
fn all_values_debounce() {
114-
async_io::block_on(async {
114+
crate::runtime::block_on(async {
115115
let interval = Duration::from_millis(10);
116116
let debounce = Duration::from_millis(20);
117117

118118
let mut counter = 0;
119-
crate::stream::interval(interval)
119+
crate::time::stream::interval(interval)
120120
.take(10)
121121
.debounce(debounce)
122122
.for_each(|_| counter += 1)
@@ -128,12 +128,12 @@ mod test {
128128

129129
#[test]
130130
fn no_debounces_hit() {
131-
async_io::block_on(async {
131+
crate::runtime::block_on(async {
132132
let interval = Duration::from_millis(40);
133133
let debounce = Duration::from_millis(10);
134134

135135
let mut counter = 0;
136-
crate::stream::interval(interval)
136+
crate::time::stream::interval(interval)
137137
.take(10)
138138
.debounce(debounce)
139139
.for_each(|_| counter += 1)

src/time/stream/sample.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ mod test {
106106

107107
#[test]
108108
fn smoke() {
109-
async_io::block_on(async {
109+
crate::runtime::block_on(async {
110110
let interval = Duration::from_millis(100);
111111
let throttle = Duration::from_millis(200);
112112

113113
let take = 4;
114114
let expected = 2;
115115

116116
let mut counter = 0;
117-
crate::stream::interval(interval)
117+
crate::time::stream::interval(interval)
118118
.take(take)
119119
.sample(throttle)
120120
.for_each(|_| counter += 1)

src/time/stream/throttle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ mod test {
109109

110110
#[test]
111111
fn smoke() {
112-
async_io::block_on(async {
112+
crate::runtime::block_on(async {
113113
let interval = Duration::from_millis(100);
114114
let throttle = Duration::from_millis(300);
115115

116116
let take = 4;
117117
let expected = 2;
118118

119119
let mut counter = 0;
120-
crate::stream::interval(interval)
120+
crate::time::stream::interval(interval)
121121
.take(take)
122122
.throttle(throttle)
123123
.for_each(|_| counter += 1)

0 commit comments

Comments
 (0)