Skip to main content

Config

Struct Config 

Source
#[non_exhaustive]
pub struct Config { pub limits: Limits, pub max_pending: usize, pub max_in_flight: usize, pub request_timeout: Option<Duration>, pub cancellation: Option<Cancellation>, pub gate: Option<Gate>, }
Available on crate feature std only.
Expand description

An endpoint’s settings.

SettingDefaultMeaning
limitsLimits::newbudgets on incoming messages
max_pending1024our requests awaiting answers; one more evicts the oldest
max_in_flight1024deferred requests being answered; more are refused with SERVER_OVERLOADED
request_timeoutnonedeadline for our requests that set none themselves
cancellationCancellation::lspthe cancel notification, both ways; None turns cancellation off
gatenonean opening request every other request must wait for

#[non_exhaustive]: start from Config::new and chain with_*.

§Examples

use std::time::Duration;
use rpc_io::{Cancellation, Config, Gate};

let lsp = Config::new()
    .with_gate(Some(Gate::new("initialize").allow("exit")))
    .with_request_timeout(Some(Duration::from_secs(30)));
let mcp = Config::new().with_cancellation(Some(Cancellation::mcp()));
assert_eq!(lsp.max_pending, 1024);
assert_eq!(mcp.cancellation.map(|c| c.id_member), Some("requestId".into()));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§limits: Limits

Budgets on incoming messages.

§max_pending: usize

Most of our requests awaiting an answer at once (at least one).

§max_in_flight: usize

Most deferred requests being answered at once.

§request_timeout: Option<Duration>

The deadline for our requests that do not set their own.

§cancellation: Option<Cancellation>

How cancellation is spelled, or None for none.

§gate: Option<Gate>

The opening request, if the protocol has one.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

The defaults in the table above.

§Examples
assert!(rpc_io::Config::new().gate.is_none());
Source

pub fn with_limits(self, limits: Limits) -> Self

Sets limits.

§Examples
use rpc_io::{Config, Limits};

let c = Config::new().with_limits(Limits::new().with_max_batch(4));
assert_eq!(c.limits.max_batch, 4);
Source

pub fn with_max_pending(self, count: usize) -> Self

Sets max_pending.

§Examples
assert_eq!(rpc_io::Config::new().with_max_pending(8).max_pending, 8);
Source

pub fn with_max_in_flight(self, count: usize) -> Self

Sets max_in_flight.

§Examples
assert_eq!(rpc_io::Config::new().with_max_in_flight(8).max_in_flight, 8);
Source

pub fn with_request_timeout(self, timeout: Option<Duration>) -> Self

Sets request_timeout.

§Examples
use std::time::Duration;

let c = rpc_io::Config::new().with_request_timeout(Some(Duration::from_secs(5)));
assert_eq!(c.request_timeout, Some(Duration::from_secs(5)));
Source

pub fn with_cancellation(self, cancellation: Option<Cancellation>) -> Self

Sets cancellation.

§Examples
assert!(rpc_io::Config::new().with_cancellation(None).cancellation.is_none());
Source

pub fn with_gate(self, gate: Option<Gate>) -> Self

Sets gate.

§Examples
use rpc_io::{Config, Gate};

let c = Config::new().with_gate(Some(Gate::new("initialize")));
assert_eq!(c.gate.map(|g| g.method), Some("initialize".into()));

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.