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/src/transport/client/example.rs b/examples/client.rs similarity index 62% rename from src/transport/client/example.rs rename to examples/client.rs index 19dcec4..e0637bc 100644 --- a/src/transport/client/example.rs +++ b/examples/client.rs @@ -1,15 +1,16 @@ // 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}; +// **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 crate::transport::client::{ApiClient, ApiClientError, ApiClientHelpers, EndpointSchema}; - +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 + pub client: String, // Placeholder for a client type, generally something allowing data requests } // Placeholder configuration struct for ExampleClient @@ -17,15 +18,15 @@ pub struct 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, + 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 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 + type Conf = ExampleClientConf; // Configuration type for ExampleClient // Instantiate a new ExampleClient async fn new(conf: Self::Conf) -> Result { @@ -37,17 +38,14 @@ impl ApiClient for ExampleClient { 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!(); + /// 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 + 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 @@ -58,11 +56,11 @@ impl ApiClient for ExampleClient { // 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 + 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 } @@ -72,4 +70,4 @@ impl ApiClient 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 +impl ApiClientHelpers for ExampleClient {}