From fb448f6055b055aa7c2345799a6c117c677bcf5c Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Tue, 30 Apr 2024 20:29:23 -0400 Subject: [PATCH] Better Documentation For factory.rs --- src/factory.rs | 53 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/factory.rs b/src/factory.rs index 90ffa30..793e0c6 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -8,19 +8,54 @@ use crate::types::Cluster; use reqwest::Client; +/// A factory for creating instances of `Helius` +/// +/// This factor allows for a centralized configuration and creation of `Helius` client so work can be done across multiple clusters at the same time. +/// Using a factory simplifies client code and enhances maintainability by ensuring that all `Helius` clients are configured consistently. pub struct HeliusFactory { api_key: String, } impl HeliusFactory { - /// Initializes a new HeliusFactory instance + /// Creates a new `HeliusFactor` capable of producing `Helius` clients + /// + /// # Arguments + /// * `api_key` - The API key used for authenticating requests made by the `Helius` clients + /// + /// # Example + /// ```rust + /// let factory = HeliusFactory::new("your_api_key_here"); + /// ``` pub fn new(api_key: &str) -> Self { HeliusFactory { api_key: api_key.to_string(), } } - /// Provides a way to create multiple Helius instances in a thread-safe manner + /// Provides a way to create multiple `Helius` clients in a thread-safe manner + /// + /// # Arguments + /// * `cluster` - The Solana cluster for which the `Helius` client will be configured + /// + /// # Returns + /// A `Result` wrapping a `Helius` client if successful + /// + /// # Errors + /// This method returns a `HeliusError` if the configuration or client instantiation fails, typically due to issues with network settings or the API key provided + /// + /// # Example + /// ```rust + /// #[tokio::main] + /// async fn main() { + /// let factory = HeliusFactory::new("your_api_key_here"); + /// + /// let helius_dev = factory.create(Cluster::Devnet).unwrap(); + /// helius_dev.request_name(...).await; + /// + /// let helius_main = factory.create(Cluster::MainnetBeta).unwrap(); + /// helius_main.request_name(...).await; + /// } + /// ``` pub fn create(&self, cluster: Cluster) -> Result { let config: Arc = Arc::new(Config::new(&self.api_key, cluster)?); let client: Client = Client::new(); @@ -33,17 +68,3 @@ impl HeliusFactory { }) } } - -// Example Usage - -// #[tokio::main] -// async fn main() { -// let api_key = "your_api_key_here"; -// let factory = HeliusFactory::new(api_key); - -// let helius_dev = factory.create(Cluster::Devnet).unwrap(); -// // helius_dev.request_name(...).await; - -// let helius_main = factory.create(Cluster::MainnetBeta).unwrap(); -// // helius_main.request_name(...).await; -// }