Skip to content

Commit 1e91009

Browse files
authored
Merge pull request #59 from sunfishcode/sunfishcode/clippy
Fix a few clippy lints.
2 parents dc4a8ea + 821b29c commit 1e91009

File tree

7 files changed

+27
-35
lines changed

7 files changed

+27
-35
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition.workspace = true
99
authors.workspace = true
1010
keywords.workspace = true
1111
categories.workspace = true
12+
repository.workspace = true
1213

1314
[features]
1415

@@ -42,7 +43,7 @@ edition = "2021"
4243
license = "MIT OR Apache-2.0 OR Apache-2.0 WITH LLVM-exception"
4344
repository = "https://github.com/yoshuawuyts/wstd"
4445
keywords = ["WebAssembly", "async", "stdlib", "Components"]
45-
categories = []
46+
categories = ["wasm", "asynchronous"]
4647
authors = [
4748
"Yoshua Wuyts <[email protected]>",
4849
"Pat Hickey <[email protected]>",

src/http/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ impl Client {
174174
}
175175

176176
fn wasi_options(&self) -> Result<Option<WasiRequestOptions>> {
177-
self.options.as_ref().map(|o| o.to_wasi()).transpose()
177+
self.options
178+
.as_ref()
179+
.map(RequestOptions::to_wasi)
180+
.transpose()
178181
}
179182
}
180183

src/http/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) fn try_into_outgoing<T>(request: Request<T>) -> Result<(OutgoingReque
3434
.map_err(|()| Error::other(format!("scheme rejected by wasi-http: {scheme:?}")))?;
3535

3636
// Set authority
37-
let authority = parts.uri.authority().map(|a| a.as_str());
37+
let authority = parts.uri.authority().map(Authority::as_str);
3838
wasi_req
3939
.set_authority(authority)
4040
.map_err(|()| Error::other(format!("authority rejected by wasi-http {authority:?}")))?;

src/io/stdio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn stdin() -> Stdin {
1515
let stream = AsyncInputStream::new(wasi::cli::stdin::get_stdin());
1616
Stdin {
1717
stream,
18-
terminput: LazyCell::new(|| wasi::cli::terminal_stdin::get_terminal_stdin()),
18+
terminput: LazyCell::new(wasi::cli::terminal_stdin::get_terminal_stdin),
1919
}
2020
}
2121

@@ -55,7 +55,7 @@ pub fn stdout() -> Stdout {
5555
let stream = AsyncOutputStream::new(wasi::cli::stdout::get_stdout());
5656
Stdout {
5757
stream,
58-
termoutput: LazyCell::new(|| wasi::cli::terminal_stdout::get_terminal_stdout()),
58+
termoutput: LazyCell::new(wasi::cli::terminal_stdout::get_terminal_stdout),
5959
}
6060
}
6161

@@ -100,7 +100,7 @@ pub fn stderr() -> Stderr {
100100
let stream = AsyncOutputStream::new(wasi::cli::stderr::get_stderr());
101101
Stderr {
102102
stream,
103-
termoutput: LazyCell::new(|| wasi::cli::terminal_stderr::get_terminal_stderr()),
103+
termoutput: LazyCell::new(wasi::cli::terminal_stderr::get_terminal_stderr),
104104
}
105105
}
106106

src/io/streams.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
use super::{AsyncPollable, AsyncRead, AsyncWrite};
2-
use std::cell::RefCell;
2+
use std::cell::OnceCell;
33
use std::io::Result;
44
use wasi::io::streams::{InputStream, OutputStream, StreamError};
55

66
#[derive(Debug)]
77
pub struct AsyncInputStream {
88
// Lazily initialized pollable, used for lifetime of stream to check readiness.
99
// Field ordering matters: this child must be dropped before stream
10-
subscription: RefCell<Option<AsyncPollable>>,
10+
subscription: OnceCell<AsyncPollable>,
1111
stream: InputStream,
1212
}
1313

1414
impl AsyncInputStream {
1515
pub fn new(stream: InputStream) -> Self {
1616
Self {
17-
subscription: RefCell::new(None),
17+
subscription: OnceCell::new(),
1818
stream,
1919
}
2020
}
2121
async fn ready(&self) {
2222
// Lazily initialize the AsyncPollable
23-
if self.subscription.borrow().is_none() {
24-
self.subscription
25-
.replace(Some(AsyncPollable::new(self.stream.subscribe())));
26-
}
23+
let subscription = self
24+
.subscription
25+
.get_or_init(|| AsyncPollable::new(self.stream.subscribe()));
2726
// Wait on readiness
28-
self.subscription
29-
.borrow()
30-
.as_ref()
31-
.expect("populated refcell")
32-
.wait_for()
33-
.await;
27+
subscription.wait_for().await;
3428
}
3529
/// Like [`AsyncRead::read`], but doesn't require a `&mut self`.
3630
pub async fn read(&self, buf: &mut [u8]) -> Result<usize> {
@@ -70,30 +64,24 @@ impl AsyncRead for AsyncInputStream {
7064
pub struct AsyncOutputStream {
7165
// Lazily initialized pollable, used for lifetime of stream to check readiness.
7266
// Field ordering matters: this child must be dropped before stream
73-
subscription: RefCell<Option<AsyncPollable>>,
67+
subscription: OnceCell<AsyncPollable>,
7468
stream: OutputStream,
7569
}
7670

7771
impl AsyncOutputStream {
7872
pub fn new(stream: OutputStream) -> Self {
7973
Self {
80-
subscription: RefCell::new(None),
74+
subscription: OnceCell::new(),
8175
stream,
8276
}
8377
}
8478
async fn ready(&self) {
8579
// Lazily initialize the AsyncPollable
86-
if self.subscription.borrow().is_none() {
87-
self.subscription
88-
.replace(Some(AsyncPollable::new(self.stream.subscribe())));
89-
}
80+
let subscription = self
81+
.subscription
82+
.get_or_init(|| AsyncPollable::new(self.stream.subscribe()));
9083
// Wait on readiness
91-
self.subscription
92-
.borrow()
93-
.as_ref()
94-
.expect("populated refcell")
95-
.wait_for()
96-
.await;
84+
subscription.wait_for().await;
9785
}
9886
/// Like [`AsyncWrite::write`], but doesn't require a `&mut self`.
9987
pub async fn write(&self, buf: &[u8]) -> Result<usize> {

src/time/duration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl From<std::time::Duration> for Duration {
118118
}
119119
}
120120

121-
impl Into<std::time::Duration> for Duration {
122-
fn into(self) -> std::time::Duration {
123-
std::time::Duration::from_nanos(self.0)
121+
impl From<Duration> for std::time::Duration {
122+
fn from(duration: Duration) -> Self {
123+
Self::from_nanos(duration.0)
124124
}
125125
}
126126

src/time/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Timer {
7272
*self = Self::after(duration);
7373
}
7474
pub fn wait(&self) -> Wait {
75-
let wait_for = self.0.as_ref().map(|pollable| pollable.wait_for());
75+
let wait_for = self.0.as_ref().map(AsyncPollable::wait_for);
7676
Wait { wait_for }
7777
}
7878
}

0 commit comments

Comments
 (0)