pub struct Builder { /* private fields */ }
Expand description
Builder for creating a new Operator instance.
§Example
use cf_r2_sdk::builder::Builder;
use cf_r2_sdk::error::Error;
use dotenvy::dotenv;
use std::env;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Error> {
// load .env file
dotenv().expect(".env file not found.");
// insert a environment variable
let bucket_name = env::var("BUCKET_NAME").expect("BUCKET_NAME not found in .env file.");
let endpoint_url: String =
env::var("ENDPOINT_URL").expect("ENDPOINT_URL not found in .env file.");
let access_key_id: String =
env::var("ACCESS_KEY_ID").expect("ACCESS_KEY_ID not found in .env file.");
let secret_access_key: String =
env::var("SECRET_ACCESS_KEY").expect("SECRET_ACCESS_KEY not found in .env file.");
let region: String = env::var("REGION").expect("REGION not found in .env file.");
let object: cf_r2_sdk::operator::Operator = Builder::new()
.set_bucket_name(bucket_name)
.set_access_key_id(access_key_id)
.set_secret_access_key(secret_access_key)
.set_endpoint(endpoint_url)
.set_region(region)
.create_client_result()?;
Ok(())
}
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Builder instance with default values.
default value of region is “auto”.
Sourcepub fn set_bucket_name(self, bucket_name: String) -> Self
pub fn set_bucket_name(self, bucket_name: String) -> Self
Set the bucket name.
Sourcepub fn set_access_key_id(self, access_key_id: String) -> Self
pub fn set_access_key_id(self, access_key_id: String) -> Self
Set the access key id.
Sourcepub fn set_secret_access_key(self, secret_access_key: String) -> Self
pub fn set_secret_access_key(self, secret_access_key: String) -> Self
Set the secret access key.
Sourcepub fn set_endpoint(self, endpoint: String) -> Self
pub fn set_endpoint(self, endpoint: String) -> Self
Set the endpoint.
Sourcepub fn set_region(self, region: String) -> Self
pub fn set_region(self, region: String) -> Self
Set the region.
Sourcepub fn create_client(&self) -> Operator
👎Deprecated since 3.1.0: use create_client_result() instead
pub fn create_client(&self) -> Operator
Create a new Operator instance.
Sourcepub fn create_client_result(&self) -> Result<Operator, BuilderError>
pub fn create_client_result(&self) -> Result<Operator, BuilderError>
Create a new Operator instance.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.