ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

A builder for constructing a Config instance in a structured manner.

The ConfigBuilder struct allows users to set configuration parameters individually, ensuring required fields are provided before building the final Config instance.

§Fields

  • region (Option<String>): Optional region value.
  • endpoint (Option<String>): Optional endpoint value.
  • disable_ssl (Option<bool>): Optional SSL flag.
  • credentials (Option<credentials::Credentials>): Optional authentication credentials.

Implementations§

Source§

impl ConfigBuilder

Implementation of the ConfigBuilder struct, which provides a fluent interface
for constructing a Config instance step-by-step.

The builder pattern allows for greater flexibility when creating configuration objects
by enabling method chaining to set individual parameters. This approach ensures
that required fields are validated before the final Config instance is created.

§Example Usage
use crate::volcengine::config::Config;  
  
let config = Config::builder()  
    .with_region("us-east-1")  
    .with_endpoint("https://example.com")  
    .with_disable_ssl(true)  
    .with_credentials(credentials)  
    .build()  
    .expect("Failed to build config");  

Each setter method in ConfigBuilder accepts an argument, modifies the corresponding
field, and returns self to allow method chaining. The build method performs final
validation and returns a Config instance or an error if mandatory fields are missing.

Source

pub fn with_region(self, region: &str) -> Self

Sets the region for the configuration.

§Arguments
  • region (&str): The service region to be set.
§Returns
  • Self: The updated ConfigBuilder instance with the specified region.
Source

pub fn with_endpoint(self, endpoint: &str) -> Self

Sets the endpoint URL for the configuration.

§Arguments
  • endpoint (&str): The service endpoint to be set.
§Returns
  • Self: The updated ConfigBuilder instance with the specified endpoint.
Source

pub fn with_disable_ssl(self, disable_ssl: bool) -> Self

Enables or disables SSL in the configuration.

§Arguments
  • disable_ssl (bool): Set to true to disable SSL, or false to enable it.
§Returns
  • Self: The updated ConfigBuilder instance with the specified SSL setting.
Source

pub fn with_credentials(self, credentials: Credentials) -> Self

Sets the credentials for the configuration.

§Arguments
  • credentials (credentials::Credentials): Authentication credentials.
§Returns
  • Self: The updated ConfigBuilder instance with the specified credentials.
Source

pub fn build(self) -> Result<Config, Error>

Builds the final Config object.

This method ensures that all required fields (such as credentials) are provided before constructing the Config instance. If any required field is missing, an error is returned.

§Returns
  • Ok(Config): The successfully built Config instance.
  • Err(error::Error): Returns an error if required fields (e.g., credentials) are missing.
§Example
let config = Config::builder()
    .with_region("us-west-2")
    .with_endpoint("https://api.volcengine.com")
    .with_disable_ssl(false)
    .with_credentials(credentials::Credentials::new("access_key", "secret_key"))
    .build();

match config {
    Ok(cfg) => println!("Configuration built successfully!"),
    Err(err) => println!("Failed to build configuration: {:?}", err),
}

Trait Implementations§

Source§

impl Default for ConfigBuilder

Provides a default implementation for ConfigBuilder,
initializing all fields to None.

This implementation ensures that when a ConfigBuilder instance is created
without any parameters, it starts with no predefined values. The user can
then set specific fields as needed before calling build().

§Default Values
  • region: None (must be provided if required for the configuration)
  • endpoint: None (must be provided if required for the configuration)
  • disable_ssl: None (defaults to false if not explicitly set)
  • credentials: None (mandatory; build() will return an error if not provided)

Using the builder pattern with a default constructor allows flexibility
while enforcing validation rules in the build() method.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,