From 42c41343909b2621f6fc12ae9caadb649a0a51e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 16 Jan 2025 10:20:20 +0000 Subject: [PATCH 1/3] fix: make invocation actually follow wit name Previously it was hardcoded to `self.0.add()` --- worker-codegen/src/wit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker-codegen/src/wit.rs b/worker-codegen/src/wit.rs index 45142c39..2ce3c648 100644 --- a/worker-codegen/src/wit.rs +++ b/worker-codegen/src/wit.rs @@ -117,7 +117,7 @@ fn expand_rpc_impl( for (name, method) in &interface.functions { println!("\tFound method: '{}'.", name); let ident = format_ident!("{}", name.to_case(Case::Snake)); - let invocation_raw = quote!(self.0.add()); + let invocation_raw = quote!(self.0.#ident()); let mut invocation_item: syn::ExprMethodCall = syn::parse2(invocation_raw)?; for (arg_name, _) in &method.params { let mut segments = syn::punctuated::Punctuated::new(); From da8a9347554dd55edfa5bce4b96807006cd0bb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 16 Jan 2025 10:20:41 +0000 Subject: [PATCH 2/3] feat: add `to_rpc` for DO stubs and generate From for wit interface --- worker-codegen/src/wit.rs | 17 ++++++++++++----- worker/src/durable.rs | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/worker-codegen/src/wit.rs b/worker-codegen/src/wit.rs index 2ce3c648..a1a4f304 100644 --- a/worker-codegen/src/wit.rs +++ b/worker-codegen/src/wit.rs @@ -91,10 +91,10 @@ fn expand_struct(struct_name: &Ident, sys_name: &Ident) -> anyhow::Result anyhow::Result { +fn expand_from_impl(struct_name: &Ident, from_type: &syn::Type) -> anyhow::Result { let impl_raw = quote!( - impl From<::worker::Fetcher> for #struct_name { - fn from(fetcher: ::worker::Fetcher) -> Self { + impl From<#from_type> for #struct_name { + fn from(fetcher: #from_type) -> Self { Self(::worker::send::SendWrapper::new(fetcher.into_rpc())) } } @@ -222,8 +222,15 @@ fn expand_wit(path: &str) -> anyhow::Result { &interface_name, &struct_name, )?)); - // From Impl - items.push(syn::Item::Impl(expand_from_impl(&struct_name)?)); + // From Impl for Fetcher and Stub + items.push(syn::Item::Impl(expand_from_impl( + &struct_name, + &syn::parse_str("::worker::Fetcher")?, + )?)); + items.push(syn::Item::Impl(expand_from_impl( + &struct_name, + &syn::parse_str("::worker::Stub")?, + )?)); } let rust_file = syn::File { diff --git a/worker/src/durable.rs b/worker/src/durable.rs index 1b2188e4..b6751e16 100644 --- a/worker/src/durable.rs +++ b/worker/src/durable.rs @@ -57,6 +57,10 @@ impl Stub { let response = JsFuture::from(promise).await?; Ok(response.dyn_into::()?.into()) } + + pub fn into_rpc(self) -> T { + self.inner.unchecked_into() + } } /// Use an ObjectNamespace to get access to Stubs for communication with a Durable Object instance. From 6968d3ed739356a423382c1c09bd36939a438d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Thu, 16 Jan 2025 11:44:28 +0000 Subject: [PATCH 3/3] fix new lints 1.84 introduced new lints. --- .github/workflows/pullrequest.yml | 2 +- worker/src/d1/mod.rs | 4 ++-- worker/src/r2/builder.rs | 8 ++++---- worker/src/r2/mod.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index db39b63c..14df4785 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -61,7 +61,7 @@ jobs: run: | sudo apt update sudo apt clean - sudo apt install -y build-essential libssl-dev netcat libc++-dev + sudo apt install -y build-essential libssl-dev netcat-traditional libc++-dev - name: Install wasmpack run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh diff --git a/worker/src/d1/mod.rs b/worker/src/d1/mod.rs index bb62b133..18f31746 100644 --- a/worker/src/d1/mod.rs +++ b/worker/src/d1/mod.rs @@ -207,13 +207,13 @@ pub trait D1Argument { fn js_value(&self) -> impl AsRef; } -impl<'a> D1Argument for D1Type<'a> { +impl D1Argument for D1Type<'_> { fn js_value(&self) -> impl AsRef { Into::::into(self) } } -impl<'a> D1Argument for D1PreparedArgument<'a> { +impl D1Argument for D1PreparedArgument<'_> { fn js_value(&self) -> impl AsRef { &self.js_value } diff --git a/worker/src/r2/builder.rs b/worker/src/r2/builder.rs index df8bce32..4f3491b7 100644 --- a/worker/src/r2/builder.rs +++ b/worker/src/r2/builder.rs @@ -20,7 +20,7 @@ pub struct GetOptionsBuilder<'bucket> { pub(crate) range: Option, } -impl<'bucket> GetOptionsBuilder<'bucket> { +impl GetOptionsBuilder<'_> { /// Specifies that the object should only be returned given satisfaction of certain conditions /// in the [R2Conditional]. Refer to [Conditional operations](https://developers.cloudflare.com/r2/runtime-apis/#conditional-operations). pub fn only_if(mut self, only_if: Conditional) -> Self { @@ -174,7 +174,7 @@ pub struct PutOptionsBuilder<'bucket> { pub(crate) checksum_algorithm: String, } -impl<'bucket> PutOptionsBuilder<'bucket> { +impl PutOptionsBuilder<'_> { /// Various HTTP headers associated with the object. Refer to [HttpMetadata]. pub fn http_metadata(mut self, metadata: HttpMetadata) -> Self { self.http_metadata = Some(metadata); @@ -265,7 +265,7 @@ pub struct CreateMultipartUploadOptionsBuilder<'bucket> { pub(crate) custom_metadata: Option>, } -impl<'bucket> CreateMultipartUploadOptionsBuilder<'bucket> { +impl CreateMultipartUploadOptionsBuilder<'_> { /// Various HTTP headers associated with the object. Refer to [HttpMetadata]. pub fn http_metadata(mut self, metadata: HttpMetadata) -> Self { self.http_metadata = Some(metadata); @@ -362,7 +362,7 @@ pub struct ListOptionsBuilder<'bucket> { pub(crate) include: Option>, } -impl<'bucket> ListOptionsBuilder<'bucket> { +impl ListOptionsBuilder<'_> { /// The number of results to return. Defaults to 1000, with a maximum of 1000. pub fn limit(mut self, limit: u32) -> Self { self.limit = Some(limit); diff --git a/worker/src/r2/mod.rs b/worker/src/r2/mod.rs index b11cb743..36869375 100644 --- a/worker/src/r2/mod.rs +++ b/worker/src/r2/mod.rs @@ -281,7 +281,7 @@ pub struct ObjectBody<'body> { inner: &'body EdgeR2ObjectBody, } -impl<'body> ObjectBody<'body> { +impl ObjectBody<'_> { /// Reads the data in the [Object] via a [ByteStream]. pub fn stream(self) -> Result { if self.inner.body_used()? {