Skip to content

Commit 0da08c4

Browse files
committed
undo migration changes
1 parent 2c72f72 commit 0da08c4

File tree

9 files changed

+52
-14
lines changed

9 files changed

+52
-14
lines changed

src/future.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pin_project! {
5353
future: F,
5454
#[pin]
5555
deadline: D,
56-
state: DelayState,
56+
state: State,
5757
}
5858
}
5959

6060
/// The internal state
6161
#[derive(Debug)]
62-
enum DelayState {
62+
enum State {
6363
Started,
6464
PollFuture,
6565
Completed,
@@ -70,7 +70,7 @@ impl<F, D> Delay<F, D> {
7070
Self {
7171
future,
7272
deadline,
73-
state: DelayState::Started,
73+
state: State::Started,
7474
}
7575
}
7676
}
@@ -82,16 +82,16 @@ impl<F: Future, D: Future> Future for Delay<F, D> {
8282
let mut this = self.project();
8383
loop {
8484
match this.state {
85-
DelayState::Started => {
85+
State::Started => {
8686
ready!(this.deadline.as_mut().poll(cx));
87-
*this.state = DelayState::PollFuture;
87+
*this.state = State::PollFuture;
8888
}
89-
DelayState::PollFuture => {
89+
State::PollFuture => {
9090
let value = ready!(this.future.as_mut().poll(cx));
91-
*this.state = DelayState::Completed;
91+
*this.state = State::Completed;
9292
return Poll::Ready(value);
9393
}
94-
DelayState::Completed => panic!("future polled after completing"),
94+
State::Completed => panic!("future polled after completing"),
9595
}
9696
}
9797
}

src/sys/p2/http/request.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use wasip2::http::types::IncomingRequest;
1212

1313
pub use http::request::{Builder, Request};
1414

15+
// TODO: go back and add json stuff???
16+
1517
pub(crate) fn try_into_outgoing<T>(request: Request<T>) -> Result<(OutgoingRequest, T), Error> {
1618
let wasi_req = OutgoingRequest::new(header_map_to_wasi(request.headers())?);
1719

src/sys/p2/http/response.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ pub(crate) fn try_from_incoming(incoming: IncomingResponse) -> Result<Response<B
2121
.expect("cannot call `consume` twice on incoming response");
2222
let body = Body::from_incoming(incoming_body, hint);
2323

24+
// The [`http::response::Builder`] keeps internal state of whether the
25+
// builder has errored, which is only reachable by passing
26+
// [`Builder::header`] an erroring `TryInto<HeaderName>` or
27+
// `TryInto<HeaderValue>`. Since the `Builder::header` method is never
28+
// used, we know `Builder::headers_mut` will never give the None case, nor
29+
// will `Builder::body` give the error case. So, rather than treat those
30+
// as control flow, we unwrap if this invariant is ever broken because
31+
// that would only be possible due to some unrecoverable bug in wstd,
32+
// rather than incorrect use or invalid input.
2433
let mut builder = Response::builder().status(status);
2534
*builder.headers_mut().expect("builder has not errored") = headers;
2635
Ok(builder

src/sys/p2/http/server.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//! HTTP servers
2+
//!
3+
//! The WASI HTTP server uses the [typed main] idiom, with a `main` function
4+
//! that takes a [`Request`] and succeeds with a [`Response`], using the
5+
//! [`http_server`] macro:
6+
//!
7+
//! ```no_run
8+
//! use wstd::http::{Request, Response, Body, Error};
9+
//! #[wstd::http_server]
10+
//! async fn main(_request: Request<Body>) -> Result<Response<Body>, Error> {
11+
//! Ok(Response::new("Hello!\n".into()))
12+
//! }
13+
//! ```
14+
//!
15+
//! [typed main]: https://sunfishcode.github.io/typed-main-wasi-presentation/chapter_1.html
16+
//! [`Request`]: crate::http::Request
17+
//! [`Responder`]: crate::http::server::Responder
18+
//! [`Response`]: crate::http::Response
19+
//! [`http_server`]: crate::http_server
20+
121
use crate::http::{Body, Error, Response, error::ErrorCode};
222
use super::fields::header_map_to_wasi;
323
use http::header::CONTENT_LENGTH;

src/sys/p2/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl AsyncInputStream {
2626
stream,
2727
}
2828
}
29-
pub(crate) fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<()> {
29+
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<()> {
3030
// Lazily initialize the AsyncPollable
3131
let subscription = self
3232
.subscription
@@ -43,7 +43,7 @@ impl AsyncInputStream {
4343
}
4444
}
4545
/// Await for read readiness.
46-
pub(crate) async fn ready(&self) {
46+
async fn ready(&self) {
4747
poll_fn(|cx| self.poll_ready(cx)).await
4848
}
4949
/// Asynchronously read from the input stream.
@@ -233,7 +233,7 @@ impl AsyncOutputStream {
233233
}
234234
}
235235
/// Await write readiness.
236-
pub(crate) async fn ready(&self) {
236+
async fn ready(&self) {
237237
// Lazily initialize the AsyncPollable
238238
let subscription = self
239239
.subscription

src/sys/p2/net/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Async network abstractions.
2+
13
use std::io::{self, ErrorKind};
24
use wasip2::sockets::network::ErrorCode;
35

@@ -7,7 +9,7 @@ mod tcp_stream;
79
pub use tcp_listener::*;
810
pub use tcp_stream::*;
911

10-
pub(crate) fn to_io_err(err: ErrorCode) -> io::Error {
12+
fn to_io_err(err: ErrorCode) -> io::Error {
1113
match err {
1214
ErrorCode::Unknown => ErrorKind::Other.into(),
1315
ErrorCode::AccessDenied => ErrorKind::PermissionDenied.into(),

src/sys/p2/random.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Random number generation.
2+
13
use wasip2::random;
24

35
/// Fill the slice with cryptographically secure random bytes.

src/sys/p2/runtime/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::future::Future;
1414
use std::pin::pin;
1515
use std::task::{Context, Poll, Waker};
1616

17-
/// Start the event loop. Blocks until the future completes.
17+
/// Start the event loop. Blocks until the future
1818
pub fn block_on<F>(fut: F) -> F::Output
1919
where
2020
F: Future,

src/sys/p2/time.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ pub fn now() -> MonotonicInstant {
1717
monotonic_clock::now()
1818
}
1919

20-
/// A measurement of the system clock.
20+
/// A measurement of the system clock, useful for talking to external entities
21+
/// like the file system or other processes. May be converted losslessly to a
22+
/// more useful `std::time::SystemTime` to provide more methods.
2123
#[derive(Debug, Clone, Copy)]
24+
#[allow(dead_code)]
2225
pub struct SystemTime(wall_clock::Datetime);
2326

2427
impl SystemTime {

0 commit comments

Comments
 (0)