From 3a3111f044f335c0445a10947db4f4cd66f25467 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Wed, 16 Oct 2024 16:06:51 +0100 Subject: [PATCH 1/2] move example client --- Cargo.lock | 270 +-------------------------------------------- Cargo.toml | 3 +- examples/client.rs | 73 ++++++++++++ 3 files changed, 76 insertions(+), 270 deletions(-) create mode 100644 examples/client.rs diff --git a/Cargo.lock b/Cargo.lock index 0ec2a60..976ea54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,12 +58,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - [[package]] name = "bitvec" version = "0.19.5" @@ -174,16 +168,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -316,57 +300,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "fastrand" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -614,19 +553,6 @@ dependencies = [ "tokio-rustls", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -682,25 +608,6 @@ dependencies = [ "hashbrown 0.14.3", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" -dependencies = [ - "libc", - "windows-sys 0.45.0", -] - [[package]] name = "ipnet" version = "2.7.2" @@ -735,7 +642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ "arrayvec", - "bitflags 1.3.2", + "bitflags", "cfg-if 1.0.0", "ryu", "static_assertions", @@ -756,12 +663,6 @@ dependencies = [ "cc", ] -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "log" version = "0.4.19" @@ -798,23 +699,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "6.1.2" @@ -859,50 +743,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.6.0", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -921,12 +761,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" - [[package]] name = "ppv-lite86" version = "0.2.8" @@ -998,15 +832,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "reqwest" version = "0.11.9" @@ -1023,13 +848,11 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", - "hyper-tls", "ipnet", "js-sys", "lazy_static", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", "rustls", @@ -1038,7 +861,6 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", - "tokio-native-tls", "tokio-rustls", "url", "wasm-bindgen", @@ -1069,20 +891,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustix" -version = "0.36.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys 0.45.0", -] - [[package]] name = "rustls" version = "0.20.4" @@ -1110,15 +918,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "schannel" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" -dependencies = [ - "windows-sys 0.48.0", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -1141,29 +940,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.189" @@ -1358,19 +1134,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "tempfile" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" -dependencies = [ - "cfg-if 1.0.0", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys 0.42.0", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -1452,16 +1215,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.23.2" @@ -1592,12 +1345,6 @@ dependencies = [ "serde", ] -[[package]] -name = "vcpkg" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" - [[package]] name = "version_check" version = "0.9.4" @@ -1776,21 +1523,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.1", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", - "windows_x86_64_gnullvm 0.42.1", - "windows_x86_64_msvc 0.42.1", -] - [[package]] name = "windows-sys" version = "0.45.0" diff --git a/Cargo.toml b/Cargo.toml index 2fd2cc2..c038c0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,4 +46,5 @@ wasm-bindgen-test = { version = "0.3.2" } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] tokio = { version = "1.28.2", features = ["rt", "macros"] } - +[[example]] +name = "client" diff --git a/examples/client.rs b/examples/client.rs new file mode 100644 index 0000000..e0637bc --- /dev/null +++ b/examples/client.rs @@ -0,0 +1,73 @@ +// THIS FILE MUST NOT INCLUDED IN WORKSPACE +// **Some Broken Code to Ensure the Build Fails if this File is Included in the Workspace** +// +// cargo run --example client +// +use async_trait::async_trait; +use serde::Deserialize; +use sia_rust::transport::client::{ApiClient, ApiClientError, ApiClientHelpers, EndpointSchema}; +use sia_rust::transport::endpoints::SiaApiRequest; + +#[derive(Clone)] +pub struct ExampleClient { + pub client: String, // Placeholder for a client type, generally something allowing data requests +} + +// Placeholder configuration struct for ExampleClient +// Generally this will hold everything neccesary to init a new instance of ExampleClient +// It can include things like authentication, timeouts, etc. +#[derive(Clone, Debug, Deserialize)] +pub struct ExampleClientConf { + pub foo: String, // Placeholders for some client specific configurations + pub bar: Option, +} + +#[async_trait] +impl ApiClient for ExampleClient { + type Request = PlaceholderRequest; // Placeholder for the request type, like `reqwest::Request` + type Response = PlaceholderResponse; // Placeholder for the response type, like `reqwest::Response` + type Conf = ExampleClientConf; // Configuration type for ExampleClient + + // Instantiate a new ExampleClient + async fn new(conf: Self::Conf) -> Result { + // Example of how you might process authentication, timeouts, etc. + todo!(); // Replace with the logic needed to build ExampleClient + } + + // Process an `EndpointSchema` and convert it into a request + fn process_schema(&self, schema: EndpointSchema) -> Result { + /// Add logic for converting the schema into a request + /// Schema is a standard format for providing a client with the information needed + /// to create their request type. + todo!(); + } + + // Convert an `SiaApiRequest` into a `Request` + fn to_data_request(&self, request: R) -> Result { + let schema = request.to_endpoint_schema()?; // Convert request to schema + self.process_schema(schema) // Process schema into a request + } + + // Execute the request and return a response + async fn execute_request(&self, request: Self::Request) -> Result { + // eg, self.client().execute(request).await + todo!(); + } + + // Dispatcher function that converts the request and handles execution + async fn dispatcher(&self, request: R) -> Result { + let request = self.to_data_request(request)?; // Convert request to data request + + // Execute the request + let response = self.execute_request(request).await?; + + // Check the response status and return the appropriate result + todo!(); // Handle status and response, similar to NativeClient's dispatcher + } +} + +// Implement the optional helper methods for ExampleClient +// Just this is needed to implement the `ApiClientHelpers` trait +// unless custom implementations for the traits methods are needed +#[async_trait] +impl ApiClientHelpers for ExampleClient {} From 62ac12b31c36f424007e81c18dc7be2a00cbb048 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Wed, 16 Oct 2024 16:09:55 +0100 Subject: [PATCH 2/2] delete example.rs from transport mod --- src/transport/client/example.rs | 75 --------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/transport/client/example.rs diff --git a/src/transport/client/example.rs b/src/transport/client/example.rs deleted file mode 100644 index 19dcec4..0000000 --- a/src/transport/client/example.rs +++ /dev/null @@ -1,75 +0,0 @@ -// THIS FILE MUST NOT INCLUDED IN WORKSPACE -**Some Broken Code to Ensure the Build Fails if this File is Included in the Workspace** - -use crate::transport::endpoints::{SiaApiRequest}; -use async_trait::async_trait; -use serde::Deserialize; -use crate::transport::client::{ApiClient, ApiClientError, ApiClientHelpers, EndpointSchema}; - - -#[derive(Clone)] -pub struct ExampleClient { - pub client: String, // Placeholder for a client type, generally something allowing data requests -} - -// Placeholder configuration struct for ExampleClient -// Generally this will hold everything neccesary to init a new instance of ExampleClient -// It can include things like authentication, timeouts, etc. -#[derive(Clone, Debug, Deserialize)] -pub struct ExampleClientConf { - pub foo: String, // Placeholders for some client specific configurations - pub bar: Option, -} - -#[async_trait] -impl ApiClient for ExampleClient { - type Request = PlaceholderRequest; // Placeholder for the request type, like `reqwest::Request` - type Response = PlaceholderResponse; // Placeholder for the response type, like `reqwest::Response` - type Conf = ExampleClientConf; // Configuration type for ExampleClient - - // Instantiate a new ExampleClient - async fn new(conf: Self::Conf) -> Result { - // Example of how you might process authentication, timeouts, etc. - todo!(); // Replace with the logic needed to build ExampleClient - } - - // Process an `EndpointSchema` and convert it into a request - fn process_schema(&self, schema: EndpointSchema) -> Result { - /// Add logic for converting the schema into a request - /// Schema is a standard format for providing a client with the information needed - /// to create their request type. - todo!(); - } - - // Convert an `SiaApiRequest` into a `Request` - fn to_data_request(&self, request: R) -> Result { - /// Convert an `SiaApiRequest` into a `Request` that can be executed - /// SiaApiRequest represents a request-response pair defining data types for input and output - /// This function converts the request into a format that ExampleClient can execute - let schema = request.to_endpoint_schema()?; // Convert request to schema - self.process_schema(schema) // Process schema into a request - } - - // Execute the request and return a response - async fn execute_request(&self, request: Self::Request) -> Result { - // eg, self.client().execute(request).await - todo!(); - } - - // Dispatcher function that converts the request and handles execution - async fn dispatcher(&self, request: R) -> Result { - let request = self.to_data_request(request)?; // Convert request to data request - - // Execute the request - let response = self.execute_request(request).await?; - - // Check the response status and return the appropriate result - todo!(); // Handle status and response, similar to NativeClient's dispatcher - } -} - -// Implement the optional helper methods for ExampleClient -// Just this is needed to implement the `ApiClientHelpers` trait -// unless custom implementations for the traits methods are needed -#[async_trait] -impl ApiClientHelpers for ExampleClient {} \ No newline at end of file