diff --git a/Cargo.lock b/Cargo.lock index 5fcc653c..b8059af1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1776,6 +1776,7 @@ version = "0.1.0" dependencies = [ "chrono", "reflectapi", + "reqwest", "serde", "tracing", ] diff --git a/docs/src/clients/README.md b/docs/src/clients/README.md index 1f3a576c..bb581d9d 100644 --- a/docs/src/clients/README.md +++ b/docs/src/clients/README.md @@ -79,7 +79,20 @@ The demo repository includes extra project scaffolding around some generated cli ### Rust - Generates typed async client methods. -- Integrates with `reflectapi::rt::Client`. +- Integrates with `reflectapi::rt::Client`. The transport carries the + base URL (`Client::base_url`); the per-request `Request` DTO carries + only `path`, `headers`, and `body` — same shape as TypeScript and + Python. +- Built-in transports: `reflectapi::rt::ReqwestClient` (a thin wrapper + around `reqwest::Client` + base URL) and the type alias + `ReqwestMiddlewareClient` for `reqwest_middleware::ClientWithMiddleware`. +- Generated `Interface` exposes: + - `Interface::new(client: C)` — generic, takes any `Client` impl. + - `Interface::try_new(reqwest::Client, base_url) -> Result` — + convenience constructor that hides the `ReqwestClient` adapter for + the most common case. Available when the generated crate enables + its own `reqwest` feature (which should re-export + `reflectapi/reqwest`). - Supports optional tracing instrumentation through `--instrument`. - Generates serde-compatible types and request helpers for JSON-based transport. diff --git a/reflectapi-demo/clients/rust/generated/Cargo.toml b/reflectapi-demo/clients/rust/generated/Cargo.toml index 1c4f1e41..347f879e 100644 --- a/reflectapi-demo/clients/rust/generated/Cargo.toml +++ b/reflectapi-demo/clients/rust/generated/Cargo.toml @@ -8,7 +8,14 @@ workspace = true [dependencies] reflectapi = { workspace = true, features = ["rt", "rt-sse", "reqwest", "chrono"] } +reqwest = { version = "0.12.2", optional = true } chrono = { version = "0.4.37", features = ["serde"] } tracing = "0.1" serde = { version = "1.0.218", features = ["derive"] } +[features] +default = ["reqwest"] +# Enables `Interface::try_new(reqwest::Client, base_url)` — a convenience +# constructor that hides the `reflectapi::rt::ReqwestClient` adapter. +reqwest = ["dep:reqwest"] + diff --git a/reflectapi-demo/clients/rust/generated/src/generated.rs b/reflectapi-demo/clients/rust/generated/src/generated.rs index d91a8759..cbb53d4b 100644 --- a/reflectapi-demo/clients/rust/generated/src/generated.rs +++ b/reflectapi-demo/clients/rust/generated/src/generated.rs @@ -17,43 +17,42 @@ pub mod interface { pub health: HealthInterface, pub pets: PetsInterface, client: C, - base_url: reflectapi::rt::Url, } impl Interface { + pub fn new(client: C) -> Self { + Self { + health: HealthInterface::new(client.clone()), + pets: PetsInterface::new(client.clone()), + client, + } + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. pub fn try_new( - client: C, + client: reqwest::Client, base_url: reflectapi::rt::Url, ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - health: HealthInterface::try_new(client.clone(), base_url.clone())?, - pets: PetsInterface::try_new(client.clone(), base_url.clone())?, - client, - base_url, - }) + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } #[derive(Debug)] pub struct HealthInterface { client: C, - base_url: reflectapi::rt::Url, } impl HealthInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } /// Check the health of the service #[tracing::instrument(name = "/health.check", skip(self, headers))] @@ -65,34 +64,18 @@ pub mod interface { reflectapi::Empty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/health.check") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/health.check", input, headers).await } } #[derive(Debug)] pub struct PetsInterface { client: C, - base_url: reflectapi::rt::Url, } impl PetsInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } /// List available pets #[tracing::instrument(name = "/pets.list", skip(self, headers))] @@ -104,15 +87,7 @@ pub mod interface { super::types::myapi::proto::Paginated, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.list") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.list", input, headers).await } /// Create a new pet #[tracing::instrument(name = "/pets.create", skip(self, headers))] @@ -124,15 +99,7 @@ pub mod interface { reflectapi::Empty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.create") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.create", input, headers).await } /// Update an existing pet #[tracing::instrument(name = "/pets.update", skip(self, headers))] @@ -144,15 +111,7 @@ pub mod interface { reflectapi::Empty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.update") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.update", input, headers).await } /// Remove an existing pet #[tracing::instrument(name = "/pets.remove", skip(self, headers))] @@ -164,15 +123,7 @@ pub mod interface { reflectapi::Empty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.remove") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.remove", input, headers).await } #[deprecated(note = "Use pets.remove instead")] /// Remove an existing pet @@ -185,15 +136,7 @@ pub mod interface { reflectapi::Empty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.delete") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.delete", input, headers).await } /// Fetch first pet, if any exists #[tracing::instrument(name = "/pets.get-first", skip(self, headers))] @@ -205,15 +148,7 @@ pub mod interface { std::option::Option, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/pets.get-first") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/pets.get-first", input, headers).await } /// Stream of change data capture events for pets #[tracing::instrument(name = "/pets.cdc-events", skip(self, headers))] @@ -229,15 +164,8 @@ pub mod interface { where C::Error: Send + 'static, { - reflectapi::rt::__stream_request_impl( - &self.client, - self.base_url - .join("/pets.cdc-events") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__stream_request_impl(&self.client, "/pets.cdc-events", input, headers) + .await } } } diff --git a/reflectapi-demo/clients/rust/src/main.rs b/reflectapi-demo/clients/rust/src/main.rs index 11b67235..8458f287 100644 --- a/reflectapi-demo/clients/rust/src/main.rs +++ b/reflectapi-demo/clients/rust/src/main.rs @@ -5,7 +5,7 @@ use reflectapi_demo_client_generated::types::myapi::model::Kind; use reflectapi_demo_client_generated::types::myapi::proto::Headers; use reflectapi_demo_client_generated::DemoServerClient; -type Client = DemoServerClient; +type Client = DemoServerClient; fn headers() -> Headers { Headers { diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_deprecated-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_deprecated-3.snap index 2ba3e1fa..4725ad53 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_deprecated-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_deprecated-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::StructWithDeprecatedField, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_documented-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_documented-3.snap index c21d4305..85e862f9 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_documented-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_documented-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::basic::TestEnumDocumented, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_with_skip_variant-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_with_skip_variant-3.snap index dcfe2c4a..42056e02 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_with_skip_variant-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_enum_with_skip_variant-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::output::TestEnumWithSkipVariant, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_documented-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_documented-3.snap index fc61c444..2ea3ef20 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_documented-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_documented-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::basic::TestStructDocumented, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_empty-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_empty-3.snap index fd92b737..509f9e24 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_empty-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_empty-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructEmpty, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_newtype-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_newtype-3.snap index 850517b0..ac5622ab 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_newtype-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_newtype-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructNewtype, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_static_str-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_static_str-3.snap index 35ef3a91..81ba2bf5 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_static_str-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_static_str-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn output_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldStaticStr, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/output_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/output_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string-3.snap index 8e877e9e..7e67e841 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldString, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both-3.snap index c1ffc4d3..33dab638 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldStringReflectBoth, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally-3.snap index 8122e8f0..6e779182 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally-3.snap @@ -19,31 +19,31 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test(&self, input: super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldStringReflectBothEqually, headers: reflectapi::Empty) -> Result>{ - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally2-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally2-3.snap index bdace3be..fbe86a4c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally2-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_equally2-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldStringReflectBothEqually, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_with_attributes-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_with_attributes-3.snap index 557a1898..7e246eaa 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_with_attributes-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_string_reflectapi_both_with_attributes-3.snap @@ -19,31 +19,31 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test(&self, input: super::types::reflectapi_demo::tests::basic::input::TestStructOneBasicFieldStringReflectBothDifferently, headers: reflectapi::Empty) -> Result>{ - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_u32-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_u32-3.snap index cd62a2ba..ffeb797f 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_u32-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_one_basic_field_u32-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::basic::TestStructOneBasicFieldU32, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_option-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_option-3.snap index f72b4d14..9b176968 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_option-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_option-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructOption, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_tuple-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_tuple-3.snap index ce894de2..34b01bc1 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_tuple-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_tuple-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructTuple, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_unit_type-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_unit_type-3.snap index 7b2e9d8a..2c07d795 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_unit_type-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_unit_type-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructUnitType, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_additional_derives-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_additional_derives-3.snap index 995683e8..8da01b73 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_additional_derives-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_additional_derives-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_all_primitive_type_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_all_primitive_type_fields-3.snap index c16c7848..2428c329 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_all_primitive_type_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_all_primitive_type_fields-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithAllPrimitiveTypeFields, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc-3.snap index f8787671..d2356801 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithArc, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc_pointer_only-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc_pointer_only-3.snap index 16d30e81..c73fb392 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc_pointer_only-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_arc_pointer_only-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithArcPointerOnly, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes-3.snap index 9e1d806f..9e7e1b9c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, input: u8, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_input_only-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_input_only-3.snap index 2e408ade..97936383 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_input_only-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_input_only-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithAttributesInputOnly, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_output_only-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_output_only-3.snap index 075c2162..3e58fb0e 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_output_only-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_output_only-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -39,15 +31,23 @@ pub mod interface { headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_type_only-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_type_only-3.snap index 87e690f2..3be218ce 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_type_only-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_attributes_type_only-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -39,15 +31,23 @@ pub mod interface { headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_external_generic_type_fallback-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_external_generic_type_fallback-3.snap index 52ec81e0..8f59722d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_external_generic_type_fallback-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_external_generic_type_fallback-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithExternalGenericTypeFallback, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_fixed_size_array-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_fixed_size_array-3.snap index 6afe1709..5552063f 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_fixed_size_array-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_fixed_size_array-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithFixedSizeArray, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashmap-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashmap-3.snap index e51bc84c..0d2c2650 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashmap-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashmap-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithHashMap, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field-3.snap index a8d62808..56a2c1d2 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithHashSetField, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field_generic-3.snap index a873f7d1..4b9f1966 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_hashset_field_generic-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -45,15 +37,23 @@ pub mod interface { >, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested-3.snap index cfe2f37c..8a74e212 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithNested, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested_external-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested_external-3.snap index 0be0f064..dc42a824 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested_external-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_nested_external-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithNestedExternal, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_self_via_arc-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_self_via_arc-3.snap index cdfda325..4c527c82 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_self_via_arc-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_self_via_arc-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithSelfViaArc, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field-3.snap index 21ca4169..48b581d1 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithSkipField, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_input-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_input-3.snap index e24444d9..f3a45517 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_input-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_input-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::output::TestStructWithSkipFieldInput, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_output-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_output-3.snap index 77e8ec3b..89a0b217 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_output-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_skip_field_output-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::output::TestStructWithSkipFieldOutput, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_array-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_array-3.snap index dc55a443..9bebfd4e 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_array-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_array-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTransformArray, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_both-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_both-3.snap index 3984898f..9348fc91 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_both-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_both-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTransformBoth, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback-3.snap index c1b68ba2..7754edb0 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTransformFallback, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback_nested-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback_nested-3.snap index 182b6ff8..3cbfea9b 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback_nested-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_fallback_nested-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTransformFallbackNested, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_input-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_input-3.snap index 90460d4f..5f9fc603 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_input-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_input-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::output::TestStructWithTransformInput, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_output-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_output-3.snap index b5842ee3..0ddce23e 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_output-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_transform_output-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::output::TestStructWithTransformOutput, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple-3.snap index bb3c76b5..f6a70316 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTuple, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple12-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple12-3.snap index a8bf5e6f..ad1d610f 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple12-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_tuple12-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithTuple12, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec-3.snap index 35722718..5b8dbc4e 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithVec, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_external-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_external-3.snap index 11d14638..5be77ec6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_external-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_external-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithVecExternal, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_nested-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_nested-3.snap index b3452c12..74ef9d53 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_nested-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_nested-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithVecNested, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_two-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_two-3.snap index 96c0983f..27983820 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_two-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__basic__reflectapi_struct_with_vec_two-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::basic::TestStructWithVecTwo, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum-3.snap index 30c935ec..aa5bb4e7 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnum, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_empty-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_empty-3.snap index 99b850f9..c7116196 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_empty-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_empty-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumEmpty, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_rename_num-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_rename_num-3.snap index e9fe0dd1..fd8fb878 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_rename_num-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_rename_num-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::enums::Nums, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_basic_variant_and_fields_and_named_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_basic_variant_and_fields_and_named_fields-3.snap index f5ebafd9..7405c01b 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_basic_variant_and_fields_and_named_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_basic_variant_and_fields_and_named_fields-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithBasicVariantAndFieldsAndNamedFields, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_input-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_input-3.snap index 8fd35ff4..1822bf6b 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_input-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_input-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithDiscriminantIgnored, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_output-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_output-3.snap index 2eed9c2c..767337bc 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_output-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_ignored_output-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn output_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::enums::TestEnumWithDiscriminantIgnored, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/output_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/output_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_input-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_input-3.snap index 93f03530..8008f5c7 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_input-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_input-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithDiscriminant, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_output-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_output-3.snap index 4aedd4ae..0858962d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_output-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_discriminant_output-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn output_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::enums::TestEnumWithDiscriminant, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/output_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/output_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_empty_variant_and_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_empty_variant_and_fields-3.snap index 930dcff1..e631fe99 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_empty_variant_and_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_empty_variant_and_fields-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithEmptyVariantAndFields, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_fields-3.snap index cb95b8ab..ab00bfe6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_fields-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithFields, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics-3.snap index 574c2826..751de645 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithGenerics, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields-3.snap index 0ca5ab25..9aa569ce 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithGenericsAndFields, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields_and_named_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields_and_named_fields-3.snap index a31a746e..1731c40b 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields_and_named_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__enum_with_generics_and_fields_and_named_fields-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::enums::TestEnumWithGenericsAndFieldsAndNamedFields, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_tuple_variants-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_tuple_variants-3.snap index b268e49e..e7a586de 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_tuple_variants-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_tuple_variants-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::enums::E, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_unit_variants-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_unit_variants-3.snap index 31fab3d3..0d144eaf 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_unit_variants-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__enums__internally_tagged_enum_with_unit_variants-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::enums::A, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference-3.snap index 6c1bc983..5014ba3d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReference, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic-3.snap index b9e928de..1bcd0146 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGeneric, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_parent-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_parent-3.snap index e88ad88b..63f4222a 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_parent-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_parent-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericParent, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box-3.snap index fb259197..02dc9824 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericWithoutBox, super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericWithoutBox>, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent-3.snap index 8711ed7b..fc38c655 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericWithoutBoxParent, super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericWithoutBoxParent>, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent_specific-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent_specific-3.snap index a94b3d77..179024aa 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent_specific-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_circular_reference_generic_without_box_parent_specific-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithCircularReferenceGenericWithoutBoxParentSpecific, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct-3.snap index 83ab6e32..2daa7293 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithNestedGenericStruct, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct_twice-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct_twice-3.snap index 3aa89247..c4df3150 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct_twice-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_nested_generic_struct_twice-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithNestedGenericStructTwice, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_simple_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_simple_generic-3.snap index 454dc5e9..214c36a8 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_simple_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_simple_generic-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithSimpleGeneric, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic-3.snap index 6dca708c..0fe55354 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithVecGeneric, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic-3.snap index 70d73284..3bea9592 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, @@ -40,15 +32,23 @@ pub mod interface { >, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic_generic-3.snap index b5508c5d..abb839a0 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__generics__struct_with_vec_generic_generic_generic-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn input_test( &self, input: super::types::reflectapi_demo::tests::generics::TestStructWithVecGenericGenericGeneric>, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/input_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/input_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_names-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_names-3.snap index ac8169ca..609f5c24 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_names-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_names-3.snap @@ -1,7 +1,6 @@ --- source: reflectapi-demo/src/tests/namespace.rs expression: rust -snapshot_kind: text --- // DO NOT MODIFY THIS FILE MANUALLY // This file was generated by reflectapi-cli @@ -21,42 +20,41 @@ pub mod interface { pub struct Interface { pub foos: FoosInterface, client: C, - base_url: reflectapi::rt::Url, } impl Interface { + pub fn new(client: C) -> Self { + Self { + foos: FoosInterface::new(client.clone()), + client, + } + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. pub fn try_new( - client: C, + client: reqwest::Client, base_url: reflectapi::rt::Url, ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - foos: FoosInterface::try_new(client.clone(), base_url.clone())?, - client, - base_url, - }) + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } #[derive(Debug)] pub struct FoosInterface { client: C, - base_url: reflectapi::rt::Url, } impl FoosInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn get( &self, @@ -64,15 +62,7 @@ pub mod interface { headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/foos.get") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/foos.get", input, headers).await } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_namespace_names-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_namespace_names-3.snap index 0934f99d..d5da82f7 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_namespace_names-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__conflicting_namespace_names-3.snap @@ -1,7 +1,6 @@ --- source: reflectapi-demo/src/tests/namespace.rs expression: rust -snapshot_kind: text --- // DO NOT MODIFY THIS FILE MANUALLY // This file was generated by reflectapi-cli @@ -22,24 +21,31 @@ pub mod interface { pub x: XInterface, pub y: YInterface, client: C, - base_url: reflectapi::rt::Url, } impl Interface { + pub fn new(client: C) -> Self { + Self { + x: XInterface::new(client.clone()), + y: YInterface::new(client.clone()), + client, + } + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. pub fn try_new( - client: C, + client: reqwest::Client, base_url: reflectapi::rt::Url, ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - x: XInterface::try_new(client.clone(), base_url.clone())?, - y: YInterface::try_new(client.clone(), base_url.clone())?, - client, - base_url, - }) + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } @@ -47,57 +53,32 @@ pub mod interface { pub struct XInterface { pub foo: XFooInterface, client: C, - base_url: reflectapi::rt::Url, } impl XInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - foo: XFooInterface::try_new(client.clone(), base_url.clone())?, + pub fn new(client: C) -> Self { + Self { + foo: XFooInterface::new(client.clone()), client, - base_url, - }) + } } } #[derive(Debug)] pub struct XFooInterface { client: C, - base_url: reflectapi::rt::Url, } impl XFooInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn get( &self, input: reflectapi::Empty, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/x.foo.get") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/x.foo.get", input, headers).await } } @@ -105,57 +86,32 @@ pub mod interface { pub struct YInterface { pub foo: YFooInterface, client: C, - base_url: reflectapi::rt::Url, } impl YInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - foo: YFooInterface::try_new(client.clone(), base_url.clone())?, + pub fn new(client: C) -> Self { + Self { + foo: YFooInterface::new(client.clone()), client, - base_url, - }) + } } } #[derive(Debug)] pub struct YFooInterface { client: C, - base_url: reflectapi::rt::Url, } impl YFooInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn get( &self, input: reflectapi::Empty, headers: reflectapi::Empty, ) -> Result<(), reflectapi::rt::Error> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/y.foo.get") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/y.foo.get", input, headers).await } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__generic_and_type_conflict-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__generic_and_type_conflict-3.snap index 8fce2d95..5db710a7 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__generic_and_type_conflict-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__generic_and_type_conflict-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn get( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::namespace::K>, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/get") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/get", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__namespace_with_dash-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__namespace_with_dash-3.snap index c753d6de..8b866cc1 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__namespace_with_dash-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__namespace__namespace_with_dash-3.snap @@ -1,7 +1,6 @@ --- source: reflectapi-demo/src/tests/namespace.rs expression: rust -snapshot_kind: text --- // DO NOT MODIFY THIS FILE MANUALLY // This file was generated by reflectapi-cli @@ -21,23 +20,30 @@ pub mod interface { pub struct Interface { pub jobs_two: JobsTwoInterface, client: C, - base_url: reflectapi::rt::Url, } impl Interface { + pub fn new(client: C) -> Self { + Self { + jobs_two: JobsTwoInterface::new(client.clone()), + client, + } + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. pub fn try_new( - client: C, + client: reqwest::Client, base_url: reflectapi::rt::Url, ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - jobs_two: JobsTwoInterface::try_new(client.clone(), base_url.clone())?, - client, - base_url, - }) + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } @@ -45,42 +51,25 @@ pub mod interface { pub struct JobsTwoInterface { pub pet_orders: JobsTwoPetOrdersInterface, client: C, - base_url: reflectapi::rt::Url, } impl JobsTwoInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { - pet_orders: JobsTwoPetOrdersInterface::try_new(client.clone(), base_url.clone())?, + pub fn new(client: C) -> Self { + Self { + pet_orders: JobsTwoPetOrdersInterface::new(client.clone()), client, - base_url, - }) + } } } #[derive(Debug)] pub struct JobsTwoPetOrdersInterface { client: C, - base_url: reflectapi::rt::Url, } impl JobsTwoPetOrdersInterface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } /// desc pub async fn list_x( @@ -90,9 +79,7 @@ pub mod interface { ) -> Result> { reflectapi::rt::__request_impl( &self.client, - self.base_url - .join("/jobs-two.pet-orders.list-x") - .expect("checked base_url already and path is valid"), + "/jobs-two.pet-orders.list-x", input, headers, ) diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__adj_repr_enum_with_untagged_variant-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__adj_repr_enum_with_untagged_variant-3.snap index 86ca82f8..0c133fdc 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__adj_repr_enum_with_untagged_variant-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__adj_repr_enum_with_untagged_variant-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__box_field_unwrapping-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__box_field_unwrapping-3.snap index f95796e8..bc2ce88d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__box_field_unwrapping-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__box_field_unwrapping-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TreeNode, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__datetime-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__datetime-3.snap index 6514a9e9..d55056af 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__datetime-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__datetime-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStruct, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_enum-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_enum-3.snap index 10044cef..5663a714 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_enum-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_enum-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Never, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_adjacently_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_adjacently_tagged-3.snap index 489cd44d..baaef808 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_adjacently_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_adjacently_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEmptyVariantsAdjacentlyTagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_externally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_externally_tagged-3.snap index 49ec8cec..61f6ecab 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_externally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_externally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEmptyVariantsExternallyTagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_internally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_internally_tagged-3.snap index b5b78055..0b4b53b4 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_internally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_internally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEmptyVariantsInterallyTagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_untagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_untagged-3.snap index e3d4431a..edec1e59 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_untagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__empty_variants_untagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEmptyVariantsUntagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_mixed_variant_types_internally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_mixed_variant_types_internally_tagged-3.snap index b0aa4aa3..ab8040d9 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_mixed_variant_types_internally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_mixed_variant_types_internally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Mixed, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename-3.snap index 6afd3963..3d62f8e3 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::MyEnum, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all-3.snap index 8123131a..68ac8486 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumRenameAll, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all_on_variant-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all_on_variant-3.snap index 9da2b437..8f1d1a1a 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all_on_variant-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_all_on_variant-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumRenameAllOnVariant, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_variant_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_variant_field-3.snap index 49f20850..fa25e096 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_variant_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_rename_variant_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumRenameVariantField, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag-3.snap index 8a1047e0..4bf04195 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumTag, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content-3.snap index d16877a1..1bb3da8d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumTagContent, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content_rename_all-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content_rename_all-3.snap index 363146b4..5bd65b6e 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content_rename_all-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_tag_content_rename_all-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumTagContentRenameAll, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_untagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_untagged-3.snap index 690bb48f..1dc3d512 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_untagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_untagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumUntagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_field_skip-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_field_skip-3.snap index 8b2f9a9e..b05514b7 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_field_skip-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_field_skip-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumWithFieldSkip, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_many_variants-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_many_variants-3.snap index a5ffe5e0..6a7669dd 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_many_variants-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_many_variants-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::LargeEnum, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_rename_to_invalid_chars-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_rename_to_invalid_chars-3.snap index e8ec43ab..61bcc514 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_rename_to_invalid_chars-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_rename_to_invalid_chars-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumWithRenameToInvalidChars, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_serde_rename_on_variants-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_serde_rename_on_variants-3.snap index 34b8e251..93771f78 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_serde_rename_on_variants-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_serde_rename_on_variants-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Action, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_other-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_other-3.snap index 2800190c..00157b9d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_other-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_other-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestEnumWithVariantOther, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip-3.snap index 8d146e1d..e55a0f6c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumWithVariantSkip, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_deserialize-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_deserialize-3.snap index 6094be35..f7269d55 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_deserialize-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_deserialize-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestEnumWithVariantSkipDeserialize, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_serialize-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_serialize-3.snap index 226325b3..0737ff0a 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_serialize-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_skip_serialize-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestEnumWithVariantSkipSerialize, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_untagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_untagged-3.snap index 59340730..31a10404 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_untagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__enum_with_variant_untagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestEnumWithVariantUntagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__external_impls-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__external_impls-3.snap index 85466a22..698884f6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__external_impls-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__external_impls-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_all_python_keywords-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_all_python_keywords-3.snap index 574c49da..ba684545 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_all_python_keywords-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_all_python_keywords-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Keywords, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_names_with_special_chars-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_names_with_special_chars-3.snap index bf7828a3..fd506130 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_names_with_special_chars-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__field_names_with_special_chars-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::SpecialNames, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_adjacently_tagged_enum_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_adjacently_tagged_enum_field-3.snap index 108e3901..aad40999 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_adjacently_tagged_enum_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_adjacently_tagged_enum_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Message, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_enum_with_unit_variants_only-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_enum_with_unit_variants_only-3.snap index 450c9930..24791530 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_enum_with_unit_variants_only-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_enum_with_unit_variants_only-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Item, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_externally_tagged_enum_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_externally_tagged_enum_field-3.snap index 73c45fef..58ff8c33 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_externally_tagged_enum_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_externally_tagged_enum_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Drawing, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged-3.snap index cf1cd467..4df362e6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged_enum_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged_enum_field-3.snap index 33d8a042..a7d110a4 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged_enum_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_internally_tagged_enum_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Offer, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_multiple_structs-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_multiple_structs-3.snap index f5774e43..e206c0dd 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_multiple_structs-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_multiple_structs-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Document, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_optional_internally_tagged_enum-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_optional_internally_tagged_enum-3.snap index 08f18b11..e004955d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_optional_internally_tagged_enum-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_optional_internally_tagged_enum-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Task, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_and_internal_enum_combined-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_and_internal_enum_combined-3.snap index bfa321e6..3a71bb64 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_and_internal_enum_combined-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_and_internal_enum_combined-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Post, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_with_nested_flatten-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_with_nested_flatten-3.snap index 92969993..b76b6411 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_with_nested_flatten-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_struct_with_nested_flatten-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Outer, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_unit-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_unit-3.snap index c6337f31..bd1dbed0 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_unit-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_unit-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -47,15 +39,23 @@ pub mod interface { >, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_untagged_enum_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_untagged_enum_field-3.snap index 49b44b7f..413f0e3c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_untagged_enum_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__flatten_untagged_enum_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Cell, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_adjacently_tagged_enum-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_adjacently_tagged_enum-3.snap index e8ab1b85..5dba331d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_adjacently_tagged_enum-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_adjacently_tagged_enum-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Tagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_externally_tagged_enum-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_externally_tagged_enum-3.snap index 6f55afde..8f04f043 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_externally_tagged_enum-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_externally_tagged_enum-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Wrapper, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent-3.snap index b0d0bb17..f43f5131 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, input: std::vec::Vec, headers: reflectapi::Empty, ) -> Result, reflectapi::rt::Error> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent_partially_generic-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent_partially_generic-3.snap index 5b4ec551..ad78c117 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent_partially_generic-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__generic_struct_repr_transparent_partially_generic-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { std::collections::HashMap, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__kebab_case-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__kebab_case-3.snap index 285e0493..9a758833 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__kebab_case-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__kebab_case-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__multiple_underscore_prefix_fields-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__multiple_underscore_prefix_fields-3.snap index 08cbfd79..6c175769 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__multiple_underscore_prefix_fields-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__multiple_underscore_prefix_fields-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Underscored, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_deeply_nested_modules-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_deeply_nested_modules-3.snap index 49e58dd4..360b80f8 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_deeply_nested_modules-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_deeply_nested_modules-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::deep::nested::inner::DeepType, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_single_segment_type-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_single_segment_type-3.snap index 700c3183..c628e375 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_single_segment_type-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_single_segment_type-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::SimpleTopLevel, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_with_numeric_start-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_with_numeric_start-3.snap index 525664c2..2caf0969 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_with_numeric_start-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__namespace_with_numeric_start-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TypeWithNumbers, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_generic_containers-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_generic_containers-3.snap index 89f050f5..f92bea21 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_generic_containers-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_generic_containers-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Complex, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums-3.snap index 71582322..b349b95c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums_minimal-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums_minimal-3.snap index 4236e107..28f27b2c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums_minimal-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__nested_internally_tagged_enums_minimal-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_adjacently_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_adjacently_tagged-3.snap index 27f114d5..0d39edc0 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_adjacently_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_adjacently_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestNewtypeVariantsAdjacentlyTagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_externally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_externally_tagged-3.snap index d2d52b1b..115cc2b4 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_externally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_externally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestNewtypeVariantsExternallyTagged, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_internally_tagged-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_internally_tagged-3.snap index d2875d4a..4d3d308d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_internally_tagged-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__newtype_variants_internally_tagged-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Enum, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__option_of_option-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__option_of_option-3.snap index d0b3c31c..2bff9bbe 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__option_of_option-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__option_of_option-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Nested, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__self_referential_struct-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__self_referential_struct-3.snap index f280e0cf..b56976d8 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__self_referential_struct-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__self_referential_struct-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Category, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_from-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_from-3.snap index 04b39467..2df6853b 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_from-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_from-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructFromProxy, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_into-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_into-3.snap index 30d3eab4..5f5e5e3c 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_into-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_into-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructInto, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename-3.snap index bf84bdb5..6f9e8d33 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::MyStruct, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all-3.snap index 9629ca0a..972954e2 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructRenameAll, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_differently-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_differently-3.snap index b675e3d5..e6a268ad 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_differently-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_differently-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructRenameAllDifferently, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_pascal_case-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_pascal_case-3.snap index 23146eb9..16f7c391 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_pascal_case-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_all_pascal_case-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructRenameAllPascalCase, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_differently-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_differently-3.snap index a3093137..a2921ea6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_differently-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_differently-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::MyStructOutput, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_field-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_field-3.snap index 04baa8d8..957386fc 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_field-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_rename_field-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructRenameField, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_repr_transparent_generic_inner_type-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_repr_transparent_generic_inner_type-3.snap index 8ee04f83..94c123b6 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_repr_transparent_generic_inner_type-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_repr_transparent_generic_inner_type-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::Test, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_try_from-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_try_from-3.snap index a917b455..cc1a3566 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_try_from-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_try_from-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructTryFormProxy, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten-3.snap index e67ff456..d2df7eb1 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructWithFlatten, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional-3.snap index 2cdf9bf3..9f83f680 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructWithFlattenOptional, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional_and_required-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional_and_required-3.snap index 106deb7a..13971b21 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional_and_required-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_flatten_optional_and_required-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructWithFlattenOptionalAndRequired, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_invalid_chars-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_invalid_chars-3.snap index 20885b56..8a0674a5 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_invalid_chars-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_invalid_chars-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructWithRenameToInvalidChars, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_kebab_case-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_kebab_case-3.snap index a165d910..b2a6ea79 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_kebab_case-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_rename_to_kebab_case-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::struct_name, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_default-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_default-3.snap index 8dfa7b8d..0d791dfc 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_default-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_default-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructWithSerdeDefault, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip-3.snap index ad7e27d8..53236f17 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStructWithSerdeSkip, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_deserialize-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_deserialize-3.snap index 4c582160..d9e950e2 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_deserialize-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_deserialize-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructWithSerdeSkipDeserialize, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize-3.snap index aad6255b..417b6726 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructWithSerdeSkipSerialize, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize_if-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize_if-3.snap index 05cf6f34..bcc04d16 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize_if-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_skip_serialize_if-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::output::TestStructWithSerdeSkipSerializeIf, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_transparent-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_transparent-3.snap index a4ec0854..cfe1b51d 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_transparent-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__struct_with_serde_transparent-3.snap @@ -19,34 +19,34 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, input: u8, headers: reflectapi::Empty, ) -> Result> { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__timezone-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__timezone-3.snap index c893f6a9..0accf2e4 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__timezone-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__timezone-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestStruct, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_struct-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_struct-3.snap index e2df29ea..c3395cf0 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_struct-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_struct-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestUnitStruct, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_tuple_struct-3.snap b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_tuple_struct-3.snap index 9b98c3cd..76c2daba 100644 --- a/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_tuple_struct-3.snap +++ b/reflectapi-demo/src/tests/snapshots/reflectapi_demo__tests__serde__unit_tuple_struct-3.snap @@ -19,19 +19,11 @@ pub mod interface { #[derive(Debug)] pub struct Interface { client: C, - base_url: reflectapi::rt::Url, } impl Interface { - pub fn try_new( - client: C, - base_url: reflectapi::rt::Url, - ) -> std::result::Result { - if base_url.cannot_be_a_base() { - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase); - } - - Ok(Self { client, base_url }) + pub fn new(client: C) -> Self { + Self { client } } pub async fn inout_test( &self, @@ -41,15 +33,23 @@ pub mod interface { super::types::reflectapi_demo::tests::serde::TestUnitTupleStruct, reflectapi::rt::Error, > { - reflectapi::rt::__request_impl( - &self.client, - self.base_url - .join("/inout_test") - .expect("checked base_url already and path is valid"), - input, - headers, - ) - .await + reflectapi::rt::__request_impl(&self.client, "/inout_test", input, headers).await + } + } + + #[cfg(feature = "reqwest")] + impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new( + client, base_url, + )?)) } } } diff --git a/reflectapi/src/codegen/rust.rs b/reflectapi/src/codegen/rust.rs index 3eb9ec6d..9f8c26a7 100644 --- a/reflectapi/src/codegen/rust.rs +++ b/reflectapi/src/codegen/rust.rs @@ -822,7 +822,7 @@ mod templates { out, " {}{}pub async fn {}(&self, input: {}, headers: {})\n\ -> Result<{}, reflectapi::rt::Error<{}, C::Error>> {{\n\ - reflectapi::rt::__request_impl(&self.client, self.base_url.join(\"{}\").expect(\"checked base_url already and path is valid\"), input, headers).await\n\ + reflectapi::rt::__request_impl(&self.client, \"{}\", input, headers).await\n\ }}", self.description, self.attributes, @@ -865,7 +865,7 @@ mod templates { " {}{}pub async fn {}(&self, input: {}, headers: {})\n\ -> reflectapi::rt::StreamResponse<{}, {}, C::Error>\n\ where C::Error: Send + 'static {{\n\ - reflectapi::rt::__stream_request_impl(&self.client, self.base_url.join(\"{}\").expect(\"checked base_url already and path is valid\"), input, headers).await\n\ + reflectapi::rt::__stream_request_impl(&self.client, \"{}\", input, headers).await\n\ }}", self.description, self.attributes, @@ -905,26 +905,21 @@ mod templates { pub fn render(&self) -> String { let mut out = format!( "\nimpl {} {{\n\ - pub fn try_new(client: C, base_url: reflectapi::rt::Url) -> std::result::Result {{\n\ - if base_url.cannot_be_a_base() {{\n\ - return Err(reflectapi::rt::UrlParseError::RelativeUrlWithCannotBeABaseBase);\n\ - }}\n\ - \n\ - Ok(Self {{", + pub fn new(client: C) -> Self {{\n\ + Self {{", self.name, ); for field in &self.fields { write!( out, - "\n {}: {}::try_new(client.clone(), base_url.clone())?,", + "\n {}: {}::new(client.clone()),", field.name, field.type_ ) .unwrap(); } out.push_str( "\n client,\n\ - base_url,\n\ - })\n\ + }\n\ }", ); for func in &self.functions { @@ -1121,18 +1116,16 @@ fn __interface_types_from_function_group( public: true, }); } - for field in [("client", "C"), ("base_url", "reflectapi::rt::Url")] { - type_template.fields.push(templates::__Field { - name: field.0.into(), - deprecation_note: None, - serde_name: field.0.into(), - description: "".into(), - type_: field.1.into(), - optional: false, - flatten: false, - public: false, - }); - } + type_template.fields.push(templates::__Field { + name: "client".into(), + deprecation_note: None, + serde_name: "client".into(), + description: "".into(), + type_: "C".into(), + optional: false, + flatten: false, + public: false, + }); for function_name in group.functions.iter() { let function = functions_by_name.get(function_name).unwrap(); @@ -1185,6 +1178,15 @@ fn __interface_types_from_function_group( let mut result = vec![type_template.render(), interface_implementation.render()]; + // For the top-level interface only, emit convenience constructors + // that hide the runtime adapter for built-in transports. With these, + // callers get the pre-refactor ergonomics back — + // `Interface::try_new(reqwest::Client::new(), base_url)` — without + // ever naming `ReqwestClient`. + if group.parent.is_empty() && name.is_empty() { + result.push(__top_level_convenience_constructors()); + } + for (subgroup_name, subgroup) in group.subgroups.iter() { result.extend(__interface_types_from_function_group( subgroup_name.clone(), @@ -1198,6 +1200,34 @@ fn __interface_types_from_function_group( result } +fn __top_level_convenience_constructors() -> String { + // Static — same shape for every generated client. We only emit the + // bare-reqwest specialisation: a second `try_new` targeting + // `reqwest_middleware::ClientWithMiddleware` would create a method- + // resolution ambiguity at call sites like `Client::try_new(...)`. + // Middleware users go one level deeper: + // Interface::new(reflectapi::rt::ReqwestClient::try_new(mw, url)?) + // + // Gated on the generated crate's own `reqwest` feature; it should + // re-export `reflectapi/reqwest` so the type names resolve. + r#" +#[cfg(feature = "reqwest")] +impl Interface> { + /// Convenience: build the client backed by a bare `reqwest::Client` + /// and the given base URL. Hides the + /// [`reflectapi::rt::ReqwestClient`] adapter so callers don't need + /// to name it. + pub fn try_new( + client: reqwest::Client, + base_url: reflectapi::rt::Url, + ) -> std::result::Result { + Ok(Self::new(reflectapi::rt::ReqwestClient::try_new(client, base_url)?)) + } +} +"# + .to_owned() +} + fn __modules_from_rendered_types( original_type_names: Vec, mut rendered_types: HashMap, diff --git a/reflectapi/src/rt.rs b/reflectapi/src/rt.rs index 9f0ff578..7dbaeaa4 100644 --- a/reflectapi/src/rt.rs +++ b/reflectapi/src/rt.rs @@ -7,9 +7,19 @@ pub fn error_to_string(error: &T) -> String { serde_json::to_string(error).unwrap_or_else(|e| format!("Failed to serialize error: {e}")) } +/// Transport contract for reflectapi-generated clients. +/// +/// Implementations carry the API base URL on the transport so the +/// per-request DTO is just `path + headers + body` — same shape as the +/// TypeScript and Python clients. Built-in implementations of `Client` +/// for raw `reqwest::Client` / `reqwest_middleware::ClientWithMiddleware` +/// don't carry a base URL, so we ship [`ReqwestClient`] / +/// [`ReqwestMiddlewareClient`] wrappers instead. pub trait Client { type Error; + fn base_url(&self) -> &Url; + fn request( &self, request: Request, @@ -18,21 +28,19 @@ pub trait Client { /// Transport request handed to user-provided [`Client`] implementations. /// +/// Carries only the per-request data: the relative `path`, headers, +/// and body. The transport joins `path` against its [`Client::base_url`] +/// to form the full URL. +/// /// `method` is intentionally absent: every reflectapi endpoint is `POST` /// by design, so transports hardcode it. If that ever changes it's a /// wire-protocol break and clients regenerate. pub struct Request { - pub url: Url, + pub path: String, pub headers: http::HeaderMap, pub body: bytes::Bytes, } -impl Request { - pub fn path(&self) -> &str { - self.url.path() - } -} - /// Transport response returned by user-provided [`Client`] implementations. #[allow(clippy::type_complexity)] pub struct Response { @@ -196,7 +204,7 @@ impl core::fmt::Debug for ProtocolErrorStage { #[doc(hidden)] pub async fn __request_impl( client: &C, - url: Url, + path: &str, body: I, headers: H, ) -> Result> @@ -212,43 +220,12 @@ where stage: ProtocolErrorStage::SerializeRequestBody, })?; let body = bytes::Bytes::from(body); - let headers = serde_json::to_value(&headers).map_err(|e| Error::Protocol { - info: e.to_string(), - stage: ProtocolErrorStage::SerializeRequestHeaders, - })?; - - let mut header_map = http::HeaderMap::new(); - match headers { - serde_json::Value::Object(headers) => { - for (k, v) in headers.into_iter() { - let v_str = match v { - serde_json::Value::String(v) => v, - v => v.to_string(), - }; - header_map.insert( - http::HeaderName::from_bytes(k.as_bytes()).map_err(|err| Error::Protocol { - info: err.to_string(), - stage: ProtocolErrorStage::SerializeRequestHeaders, - })?, - http::HeaderValue::from_str(&v_str).map_err(|err| Error::Protocol { - info: err.to_string(), - stage: ProtocolErrorStage::SerializeRequestHeaders, - })?, - ); - } - } - serde_json::Value::Null => {} - _ => { - return Err(Error::Protocol { - info: "Headers must be an object".to_string(), - stage: ProtocolErrorStage::SerializeRequestHeaders, - }); - } - } + let header_map = __serialize_headers_into(headers, http::HeaderMap::new()) + .map_err(|(info, stage)| Error::Protocol { info, stage })?; let response = client .request(Request { - url, + path: path.to_owned(), headers: header_map, body, }) @@ -280,14 +257,21 @@ where fn __serialize_headers_for_stream( headers: H, ) -> Result { - let headers = serde_json::to_value(&headers) - .map_err(|e| (e.to_string(), ProtocolErrorStage::SerializeRequestHeaders))?; - let mut header_map = http::HeaderMap::new(); header_map.insert( http::header::ACCEPT, http::HeaderValue::from_static("text/event-stream"), ); + __serialize_headers_into(headers, header_map) +} + +fn __serialize_headers_into( + headers: H, + mut header_map: http::HeaderMap, +) -> Result { + let headers = serde_json::to_value(&headers) + .map_err(|e| (e.to_string(), ProtocolErrorStage::SerializeRequestHeaders))?; + match headers { serde_json::Value::Object(headers) => { for (k, v) in headers.into_iter() { @@ -320,7 +304,7 @@ fn __serialize_headers_for_stream( #[cfg(feature = "rt-sse")] pub async fn __stream_request_impl( client: &C, - url: Url, + path: &str, body: I, headers: H, ) -> Result>>, Error> @@ -347,7 +331,7 @@ where let response = client .request(Request { - url, + path: path.to_owned(), headers: header_map, body, }) @@ -407,13 +391,54 @@ async fn __collect_byte_stream( Ok(buf.freeze()) } +/// Built-in [`Client`] adapter pairing a reqwest-style HTTP client with +/// a base URL. The default `T` is [`reqwest::Client`]; the type alias +/// [`ReqwestMiddlewareClient`] specialises it for +/// `reqwest_middleware::ClientWithMiddleware`. +/// +/// Reqwest's own client doesn't carry a base URL, so we pair them at +/// this layer — generated `Interface` types then only need to hold +/// the transport, and the base URL lives in exactly one place. +#[cfg(feature = "reqwest")] +#[derive(Clone, Debug)] +pub struct ReqwestClient { + pub inner: T, + pub base_url: Url, +} + +#[cfg(feature = "reqwest")] +impl ReqwestClient { + /// Pair a reqwest-style client with a base URL. + /// + /// Returns [`UrlParseError::RelativeUrlWithCannotBeABaseBase`] when + /// `base_url` cannot serve as a base (e.g. `mailto:` or a relative + /// reference). This is the same precondition the previous + /// `Interface::try_new` used to enforce. + pub fn try_new(inner: T, base_url: Url) -> Result { + if base_url.cannot_be_a_base() { + return Err(UrlParseError::RelativeUrlWithCannotBeABaseBase); + } + Ok(Self { inner, base_url }) + } +} + +/// Convenience alias for the middleware-decorated reqwest transport. +#[cfg(feature = "reqwest-middleware")] +pub type ReqwestMiddlewareClient = ReqwestClient; + #[cfg(feature = "reqwest")] -impl Client for reqwest::Client { +impl Client for ReqwestClient { type Error = reqwest::Error; + fn base_url(&self) -> &Url { + &self.base_url + } + async fn request(&self, request: Request) -> Result, Self::Error> { + let url = __join_base_path(&self.base_url, &request.path); let response = self - .request(http::Method::POST, request.url) + .inner + .request(http::Method::POST, url) .headers(request.headers) .body(request.body) .send() @@ -427,12 +452,18 @@ impl Client for reqwest::Client { } #[cfg(feature = "reqwest-middleware")] -impl Client for reqwest_middleware::ClientWithMiddleware { +impl Client for ReqwestClient { type Error = reqwest_middleware::Error; + fn base_url(&self) -> &Url { + &self.base_url + } + async fn request(&self, request: Request) -> Result, Self::Error> { + let url = __join_base_path(&self.base_url, &request.path); let response = self - .request(http::Method::POST, request.url) + .inner + .request(http::Method::POST, url) .headers(request.headers) .body(request.body) .send() @@ -447,19 +478,34 @@ impl Client for reqwest_middleware::ClientWithMiddleware { } } +#[cfg(any(feature = "reqwest", feature = "reqwest-middleware"))] +fn __join_base_path(base: &Url, path: &str) -> Url { + // `Url::join` handles the cases the codegen actually emits (paths + // beginning with "/api/...") plus malformed paths. Falls back to + // returning the base URL unchanged on parse failure, which then + // surfaces as a transport-level error from the HTTP client. + base.join(path).unwrap_or_else(|_| base.clone()) +} + #[cfg(test)] mod tests { use super::*; use futures_util::stream; #[derive(Clone)] - struct ShapeClient; + struct ShapeClient { + base_url: Url, + } impl Client for ShapeClient { type Error = std::convert::Infallible; + fn base_url(&self) -> &Url { + &self.base_url + } + async fn request(&self, request: Request) -> Result, Self::Error> { - assert_eq!(request.path(), "/shape.test"); + assert_eq!(request.path, "/shape.test"); assert_eq!(request.body.as_ref(), br#"{"name":"input"}"#); Ok(Response { @@ -487,6 +533,9 @@ mod tests { #[test] fn client_request_shape_is_used() { + let client = ShapeClient { + base_url: Url::parse("https://example.com").unwrap(), + }; let output = futures::executor::block_on(__request_impl::< _, _, @@ -494,8 +543,8 @@ mod tests { ShapeResponse, ShapeError, >( - &ShapeClient, - Url::parse("https://example.com/shape.test").unwrap(), + &client, + "/shape.test", ShapeRequest { name: "input".to_string(), },