Skip to main content

Gate

Struct Gate 

Source
#[non_exhaustive]
pub struct Gate { pub method: Cow<'static, str>, pub code: ErrorCode, pub allow: Vec<Cow<'static, str>>, }
Available on crate feature std only.
Expand description

An opening request that must succeed before anything else is served (LSP’s initialize, MCP’s initialize, LexerSketch’s auth).

Until the opening request has been answered successfully:

  • other requests are answered with code (default SERVER_NOT_INITIALIZED);
  • notifications are dropped (reported as Event::Dropped), except the methods in allow (LSP’s exit);
  • everything this side sends other than responses (notifications and requests, from handlers or other threads) is held back, then sent in order right after the opening response; if the opening request fails, what was held is discarded and held requests end with CallError::Cancelled. A held request that times out or is cancelled is simply never sent, and an “answer” to one is treated as unmatched: the peer has never seen it.

The opening request fails when it is answered with an error, and also when the peer cancels it under a Cancellation that sends no reply; the gate then shuts again and a new opening request is served. Afterwards (once it succeeded) a repeated opening request is answered with INVALID_REQUEST, as is an opening request inside a batch. A gate belongs on the side that receives the opening request; on the side that sends it, it would hold that side’s own messages forever.

Held messages are kept in memory without a limit (only requests are bounded, by Config::max_pending): send little before the gate opens.

§Examples

use rpc_io::{ErrorCode, Gate};

let gate = Gate::new("initialize").allow("exit");
assert_eq!(gate.code, ErrorCode::SERVER_NOT_INITIALIZED);
assert_eq!(gate.allow, ["exit"]);

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.
§method: Cow<'static, str>

The opening request’s method.

§code: ErrorCode

The error code for requests that arrive before the gate opens.

§allow: Vec<Cow<'static, str>>

Notifications delivered even before the gate opens.

Implementations§

Source§

impl Gate

Source

pub fn new(method: impl Into<Cow<'static, str>>) -> Self

A gate opened by a successful method request.

§Examples
assert!(rpc_io::Gate::new("auth").allow.is_empty());
Source

pub fn allow(self, method: impl Into<Cow<'static, str>>) -> Self

Lets the notification method through before the gate opens.

§Examples
let gate = rpc_io::Gate::new("initialize").allow("exit").allow("$/logTrace");
assert_eq!(gate.allow.len(), 2);
Source

pub fn with_code(self, code: ErrorCode) -> Self

Sets the error code for requests before the gate opens.

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

assert_eq!(Gate::new("auth").with_code(ErrorCode(1010)).code, ErrorCode(1010));

Trait Implementations§

Source§

impl Clone for Gate

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 Gate

Source§

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

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

impl Eq for Gate

Source§

impl Hash for Gate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Gate

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 Gate

Auto Trait Implementations§

§

impl Freeze for Gate

§

impl RefUnwindSafe for Gate

§

impl Send for Gate

§

impl Sync for Gate

§

impl Unpin for Gate

§

impl UnsafeUnpin for Gate

§

impl UnwindSafe for Gate

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.