Skip to main content

NodeConfig

Struct NodeConfig 

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

Configuration for a single Typesense node.

Use this to customize the HTTP client for specific nodes, for example to add custom TLS root certificates or configure proxies.

For simple cases, you can pass a plain URL string to the builder’s .nodes() method, which will be automatically converted.

§Examples

use typesense::NodeConfig;

// Simple URL (same as passing a string directly)
let node = NodeConfig::new("https://node1.example.com");

// With custom HTTP client configuration
// (add timeouts, headers, TLS, etc. on native targets)
let node = NodeConfig::new("https://node2.example.com")
    .http_builder(|builder| {
        // This closure receives a `reqwest::ClientBuilder` and must return it.
        // You can call any supported builder methods here; for example,
        // `builder.connect_timeout(...)` on native targets.
        builder
    });

Implementations§

Source§

impl NodeConfig

Source

pub fn new(url: impl Into<String>) -> Self

Creates a new NodeConfig with the given URL.

Source

pub fn http_builder( self, f: impl FnOnce(ClientBuilder) -> ClientBuilder + 'static, ) -> Self

Sets a custom HTTP client builder for this node.

The closure receives a default reqwest::ClientBuilder and should return a configured builder. This is useful for adding custom TLS certificates, proxies, or other reqwest settings.

When not set, a default builder with a 5-second connect timeout is used (native targets only; WASM uses the browser’s defaults).

§Examples
#[cfg(not(target_family = "wasm"))]
{
use typesense::NodeConfig;

let cert = cert();
// You can capture arbitrary configuration here (certs, proxies, etc.)
// and apply it to the `reqwest::ClientBuilder` on platforms that support it.
let node = NodeConfig::new("https://secure.example.com")
    .http_builder(move |builder| {
        builder
            .add_root_certificate(cert)
            .connect_timeout(std::time::Duration::from_secs(10))
    });
}
§Multiple nodes with the same configuration

The closure is FnOnce, so it is consumed when the HTTP client for that node is built. To use the same configuration (e.g. the same TLS certificate) for multiple nodes, clone the value once per node when building the configs:

#[cfg(not(target_family = "wasm"))]
{
use typesense::{Client, NodeConfig};

let cert = cert();
let nodes = ["https://node1:8108", "https://node2:8108"]
    .into_iter()
    .map(|url| {
        let cert_for_node = cert.clone();
        NodeConfig::new(url).http_builder(move |b| {
            b.add_root_certificate(cert_for_node)
        })
    })
    .collect::<Vec<_>>();
let _client = Client::builder().nodes(nodes).api_key("key").build();
}

Trait Implementations§

Source§

impl Debug for NodeConfig

Source§

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

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

impl<'a> From<&'a str> for NodeConfig

Source§

fn from(url: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for NodeConfig

Source§

fn from(url: String) -> Self

Converts to this type from the input type.
Source§

impl From<Url> for NodeConfig

Source§

fn from(url: Url) -> Self

Converts to this type from the input type.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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