From e36c284fad53591692c803adbd1a59bcca5a02ab Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Tue, 30 Apr 2024 20:40:55 -0400 Subject: [PATCH] Better Documentation For client.rs and Formatting --- src/client.rs | 25 +++++++++++++++++++++++-- src/factory.rs | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index a68bfde..bf01c41 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] use std::sync::Arc; use crate::config::Config; @@ -8,14 +7,33 @@ use crate::types::Cluster; use reqwest::Client; +/// The `Helius` struct is the main entry point to interacting with the SDK +/// +/// This client is responsible for setting up the network and configuration settins used to interact with the various provided methods. +/// It also provides methods to access RPC client functionalities. The client ensures thread-safe access to the underlying RPC client pub struct Helius { + /// The configuration which specifies an `api_key`, `cluster`, and the requisite `endpoints` pub config: Arc, + /// An HTTP client used for making API requests. The client is reused for all requests made through this instance of `Helius` pub client: Client, + /// A reference-counted RPC client tailored for making requests in a thread-safe manner pub rpc_client: Arc, } impl Helius { - /// Initializes a new instance of Helius + /// Creates a new instance of `Helius` configured with a specific API key and a target cluster + /// + /// # Arguments + /// * `api_key` - The API key required for authenticating requests made + /// * `cluster` - The Solana cluster (Devnet or MainnetBeta) that defines the given network environment + /// + /// # Returns + /// An instance of `Helius` if successful. A `HeliusError` is returned if an error occurs during configuration or initialization of the HTTP or RPC client + /// + /// # Example + /// ```rust + /// let helius = Helius::new("your_api_key", Cluster::Devnet).expect("Failed to create a Helius client") + /// ``` pub fn new(api_key: &str, cluster: Cluster) -> Result { let config: Arc = Arc::new(Config::new(api_key, cluster)?); let client: Client = Client::new(); @@ -29,6 +47,9 @@ impl Helius { } /// Provides a thread-safe way to access RPC functionalities + /// + /// # Returns + /// A cloned `Arc` that can be safely shared across threads pub fn rpc(&self) -> Arc { self.rpc_client.clone() } diff --git a/src/factory.rs b/src/factory.rs index 793e0c6..41b4046 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -10,7 +10,7 @@ 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. +/// 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,