Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kflansburg committed Jan 23, 2024
1 parent d862599 commit e7caadc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
6 changes: 5 additions & 1 deletion worker-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use std::{
use router_service::unsync::Router;
use serde::{Deserialize, Serialize};
use tower::Service;
use worker::{body::Body, http::{Response, HttpClone, RequestRedirect}, *};
use worker::{
body::Body,
http::{HttpClone, RequestRedirect, Response},
*,
};

mod alarm;
mod counter;
Expand Down
2 changes: 1 addition & 1 deletion worker-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Low-level extern definitions / FFI bindings to the Cloudflare Wor
[dependencies]
cfg-if = "1.0.0"
js-sys = "0.3.63"
wasm-bindgen = "=0.2.87"
wasm-bindgen = {workspace=true}

[dependencies.web-sys]
version = "0.3.63"
Expand Down
30 changes: 16 additions & 14 deletions worker/src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::{
task::{Context, Poll},
};

use bytes::Bytes;
use futures_util::{AsyncRead, Stream};
use http::HeaderMap;
use serde::de::DeserializeOwned;
use crate::console_log;

Check warning on line 6 in worker/src/body/body.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `crate::console_log`

Check warning on line 6 in worker/src/body/body.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `crate::console_log`
use crate::{
body::{wasm::WasmStreamBody, HttpBody},
futures::SendJsFuture,
Error,
};
use bytes::Bytes;
use futures_util::{AsyncRead, Stream};
use http::HeaderMap;
use serde::de::DeserializeOwned;

type BoxBody = http_body::combinators::UnsyncBoxBody<Bytes, Error>;

Expand Down Expand Up @@ -189,11 +189,13 @@ impl Body {
match self.into_inner() {
crate::body::BodyInner::Request(req) => req.body(),
crate::body::BodyInner::Response(res) => res.body(),
crate::body::BodyInner::Regular(s) => {
Some(
wasm_streams::ReadableStream::from_async_read(crate::body::BoxBodyReader::new(s), 1024).into_raw()
crate::body::BodyInner::Regular(s) => Some(
wasm_streams::ReadableStream::from_async_read(
crate::body::BoxBodyReader::new(s),
1024,
)
}
.into_raw(),
),
crate::body::BodyInner::None => None,
_ => panic!("unexpected body inner"),

Check warning on line 200 in worker/src/body/body.rs

View workflow job for this annotation

GitHub Actions / Test

unreachable pattern

Check warning on line 200 in worker/src/body/body.rs

View workflow job for this annotation

GitHub Actions / Test

unreachable pattern
}
Expand Down Expand Up @@ -302,14 +304,14 @@ impl HttpBody for Body {

pub struct BoxBodyReader {
inner: BoxBody,
store: Vec<u8>
store: Vec<u8>,
}

impl BoxBodyReader {
pub fn new(inner: BoxBody) -> Self {
BoxBodyReader {
inner,
store: Vec::new()
store: Vec::new(),
}
}
}
Expand All @@ -319,7 +321,7 @@ impl AsyncRead for BoxBodyReader {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
buf: &mut [u8],
) -> Poll<Result<usize, std::io::Error>> {
if self.store.len() > 0 {
let size = self.store.len().min(buf.len());
Expand All @@ -338,13 +340,13 @@ impl AsyncRead for BoxBodyReader {
buf[..size].clone_from_slice(&self.store[..size]);
self.store = self.store.split_off(size);
Poll::Ready(Ok(size))
},
}
Err(e) => {
Poll::Ready(Err(std::io::Error::new(std::io::ErrorKind::Other, e)))
}
},
None => Poll::Ready(Ok(0)) // Not sure about this
}
None => Poll::Ready(Ok(0)), // Not sure about this
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion worker/src/durable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ use futures_util::Future;
use js_sys::{Map, Number, Object};
use serde::{de::DeserializeOwned, Serialize};
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen_futures::future_to_promise;
use worker_sys::{
DurableObject as EdgeDurableObject, DurableObjectId,
DurableObjectNamespace as EdgeObjectNamespace, DurableObjectState, DurableObjectStorage,
DurableObjectTransaction,
};
use wasm_bindgen_futures::future_to_promise;

/// A Durable Object stub is a client object used to send requests to a remote Durable Object.
pub struct Stub {
Expand Down

0 comments on commit e7caadc

Please sign in to comment.