use crate::{
agent::{AgentConfig, ReplicaV2Transport},
Agent, AgentError, Identity, NonceFactory,
};
use std::sync::Arc;
pub struct AgentBuilder {
config: AgentConfig,
}
impl Default for AgentBuilder {
fn default() -> Self {
Self {
config: Default::default(),
}
}
}
impl AgentBuilder {
pub fn build(self) -> Result<Agent, AgentError> {
Agent::new(self.config)
}
#[cfg(feature = "reqwest")]
#[deprecated(since = "0.3.0", note = "Prefer using with_transport().")]
pub fn with_url<S: Into<String>>(self, url: S) -> Self {
use crate::agent::http_transport::ReqwestHttpReplicaV2Transport;
self.with_transport(ReqwestHttpReplicaV2Transport::create(url).unwrap())
}
pub fn with_transport<F: 'static + ReplicaV2Transport + Send + Sync>(
self,
transport: F,
) -> Self {
Self {
config: AgentConfig {
transport: Some(Arc::new(transport)),
..self.config
},
}
}
pub fn with_nonce_factory(self, nonce_factory: NonceFactory) -> Self {
AgentBuilder {
config: AgentConfig {
nonce_factory,
..self.config
},
}
}
pub fn with_identity<I>(self, identity: I) -> Self
where
I: 'static + Identity + Send + Sync,
{
AgentBuilder {
config: AgentConfig {
identity: Arc::new(identity),
..self.config
},
}
}
pub fn with_boxed_identity(self, identity: Box<dyn Identity + Send + Sync>) -> Self {
AgentBuilder {
config: AgentConfig {
identity: Arc::from(identity),
..self.config
},
}
}
pub fn with_ingress_expiry(self, duration: Option<std::time::Duration>) -> Self {
AgentBuilder {
config: AgentConfig {
ingress_expiry_duration: duration,
..self.config
},
}
}
}