use crate::hosts::solr_host::SolrHost;
use crate::models::auth::SolrAuth;
use crate::queries::request_builder::LoggingPolicy;
use std::sync::Arc;
#[derive(Clone)]
pub struct SolrServerContextBuilder {
pub(crate) host: Arc<dyn SolrHost + Send + Sync>,
pub(crate) auth: Option<Arc<dyn SolrAuth + Send + Sync>>,
pub(crate) client: Option<reqwest::Client>,
pub(crate) logging_policy: LoggingPolicy,
}
impl SolrServerContextBuilder {
pub fn new<A: SolrHost + Send + Sync + 'static>(host: A) -> Self {
Self {
host: Arc::new(host),
auth: None,
client: None,
logging_policy: LoggingPolicy::Fast(512),
}
}
pub fn with_auth(mut self, auth: impl SolrAuth + Send + Sync + 'static) -> Self {
self.auth = Some(Arc::new(auth));
self
}
pub fn with_client(mut self, client: reqwest::Client) -> Self {
self.client = Some(client);
self
}
pub fn with_logging_policy(mut self, logging_policy: LoggingPolicy) -> Self {
self.logging_policy = logging_policy;
self
}
pub fn build(self) -> SolrServerContext {
self.into()
}
}
#[derive(Clone)]
pub struct SolrServerContext {
pub(crate) host: Arc<dyn SolrHost + Send + Sync>,
pub(crate) auth: Option<Arc<dyn SolrAuth + Send + Sync>>,
pub(crate) client: reqwest::Client,
pub(crate) logging_policy: LoggingPolicy,
}
impl From<SolrServerContextBuilder> for SolrServerContext {
fn from(builder: SolrServerContextBuilder) -> Self {
Self {
host: builder.host,
auth: builder.auth,
client: builder.client.unwrap_or_default(),
logging_policy: builder.logging_policy,
}
}
}
impl From<&SolrServerContext> for SolrServerContext {
fn from(context: &SolrServerContext) -> Self {
context.clone()
}
}
impl AsRef<SolrServerContext> for SolrServerContext {
fn as_ref(&self) -> &SolrServerContext {
self
}
}