pub trait ClientFactory<T>where
T: Client,{
// Required method
fn create<'life0, 'async_trait>(
&'life0 self,
opts: ClientOptions,
) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A factory trait for creating clients with specified options. This trait is asynchronous and can be implemented for different client types.
§Examples
use rcfe_core::{
ClientFactory,
ClientOptions,
DefaultClientFactory,
Error
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let factory = DefaultClientFactory;
let options = ClientOptions::builder()
.endpoints(vec!["http://localhost:2379"])
.build();
let client = factory.create(options).await?;
println!("Client created with options: {:?}", client.get_options());
Ok(())
}Required Methods§
Sourcefn create<'life0, 'async_trait>(
&'life0 self,
opts: ClientOptions,
) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>(
&'life0 self,
opts: ClientOptions,
) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously creates a client with the given options.
§Arguments
opts- The client options to configure the client.
§Returns
Result<T, Error>- The created client or an error if creation fails.
§Examples
use rcfe_core::{
ClientFactory,
ClientOptions,
DefaultClientFactory,
Error
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let factory = DefaultClientFactory;
let options = ClientOptions::builder()
.endpoints(vec!["http://localhost:2379"])
.build();
let client = factory.create(options).await?;
println!("Client created with options: {:?}", client.get_options());
Ok(())
}§Errors
Returns an Error if the client creation fails.