#[non_exhaustive]pub struct Gate {
pub method: Cow<'static, str>,
pub code: ErrorCode,
pub allow: Vec<Cow<'static, str>>,
}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(defaultSERVER_NOT_INITIALIZED); - notifications are dropped (reported as
Event::Dropped), except the methods inallow(LSP’sexit); - 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
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: ErrorCodeThe 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
impl Gate
Sourcepub fn new(method: impl Into<Cow<'static, str>>) -> Self
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());