Struct utapi_rs::config::UploadthingConfigBuilder
source · pub struct UploadthingConfigBuilder { /* private fields */ }
Expand description
A builder for UploadthingConfig
.
This builder allows for a fluent interface to construct a UploadthingConfig
instance with custom values. It starts with default values and allows the
user to set properties such as host, user agent, API key, and version
before building the final configuration object.
Implementations§
source§impl UploadthingConfigBuilder
impl UploadthingConfigBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new UploadthingConfigBuilder
with default configuration values.
This uses UploadthingConfig::default()
to initialize the internal config
with default values.
sourcepub fn user_agent(self, user_agent: &str) -> Self
pub fn user_agent(self, user_agent: &str) -> Self
sourcepub fn api_key(self, api_key: &str) -> Self
pub fn api_key(self, api_key: &str) -> Self
Sets the API key in the configuration.
This method allows the user to provide an API key as a string slice
that will be used for authenticating with the Uploadthing service.
It attempts to parse the provided string into an ApiKey
instance
using the FromStr
trait implementation for ApiKey
. If parsing is
successful, the ApiKey
is wrapped in a Some
and set in the configuration.
If parsing fails, it falls back to the default ApiKey
which is obtained
from the environment variable UPLOADTHING_SECRET
.
§Arguments
api_key
- A string slice that represents the API key for authenticating with the service.
§Examples
let builder = UploadthingConfigBuilder::new().api_key("your_api_key");
§Panics
This method will panic if the provided api_key
string is not in a valid format
and there is no UPLOADTHING_SECRET
environment variable set to fall back on.
sourcepub fn build(self) -> UploadthingConfig
pub fn build(self) -> UploadthingConfig
Builds the UploadthingConfig
with the current settings of the builder.
Consumes the builder and returns the configured UploadthingConfig
instance.
§Examples
let config = UploadthingConfigBuilder::new()
.host("https://example.com")
.user_agent("MyUploader/1.0")
.api_key("your_api_key")
.version("2.0.0")
.build();
Trait Implementations§
source§impl Default for UploadthingConfigBuilder
impl Default for UploadthingConfigBuilder
Implements the Default
trait for UploadthingConfigBuilder
.
This allows for the creation of a builder with the default configuration
by calling UploadthingConfigBuilder::default()
.