dsh_api::dsh_api_client_factory

Struct DshApiClientFactory

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

§Factory for DSH API client

Implementations§

Source§

impl DshApiClientFactory

Source

pub fn new() -> DshApiClientFactory

§Create default factory for DSH API client

This function will create a new DshApiClientFactory from the default environment variables.

§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;

let client_factory = DshApiClientFactory::new();
if let Ok(client) = client_factory.client().await {
  println!("rest api version is {}", client.api_version());
}
§Panics

This function will panic if it cannot create a new DshApiClientFactory from the default environment variables. If you want to capture such a failure, use the create() function.

Source

pub fn create(tenant: DshApiTenant, secret: String) -> Result<Self, DshApiError>

§Create factory for DSH API client

This function will create a new DshApiClientFactory from the provided parameters.

§Parameters
  • tenant - Tenant struct, containing the platform, tenant name and the tenant’s group and user id.
  • secret - The secret used to retrieve the DSH API tokens.
§Returns
  • Ok<DshApiClientFactory> - the created client factory
  • Err<String> - when the client factory could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;
use dsh_api::dsh_api_tenant::DshApiTenant;

let secret = "...".to_string();
let tenant = DshApiTenant::from_tenant("greenbox".to_string())?;
let client_factory = DshApiClientFactory::create(tenant, secret)?;
let client = client_factory.client().await?;
println!("rest api version is {}", client.api_version());
Source

pub fn try_default() -> Result<Self, DshApiError>

§Create default factory for DSH API client

This function will create a new DshApiClientFactory from the default platform and tenant.

§Returns
  • Ok<DshApiClientFactory> - the created client factory
  • Err<String> - when the client factory could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;

let client_factory = DshApiClientFactory::try_default()?;
let client = client_factory.client().await?;
println!("rest api version is {}", client.api_version());
Source

pub fn platform(&self) -> &DshPlatform

§Returns the factories platform
Source

pub fn tenant(&self) -> &DshApiTenant

§Returns the factories tenant
Source

pub fn tenant_name(&self) -> &str

§Returns the name of the factories tenant
Source

pub fn guid(&self) -> u16

§Returns the group and user id of the factories tenant
Source

pub async fn client(&self) -> Result<DshApiClient<'_>, DshApiError>

§Create an DSH API client

This function will create a new DshApiClient.

§Returns
  • Ok<DshApiClient> - the created client
  • Err<String> - error message when the client could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;

let client_factory = DshApiClientFactory::new();
match client_factory.client().await {
  Ok(client) => println!("rest api version is {}", client.api_version()),
  Err(error) => println!("could not create client ({})", error),
}

Trait Implementations§

Source§

impl Debug for DshApiClientFactory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DshApiClientFactory

Source§

fn default() -> Self

§Create default factory for DSH API client

For the explanation, see the new() function, which delegates to the default implementation.

§Panics

This function will panic if it cannot create a new DshApiClientFactory from the default environment variables. If you want to capture such a failure, use the create() function.

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
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<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,

Source§

impl<T> MaybeSendSync for T