Skip to main content

RequestDispatcher

Struct RequestDispatcher 

Source
pub(crate) struct RequestDispatcher<'a> {
    pub(crate) req: Option<Request>,
    pub(crate) global_state: &'a mut GlobalState,
}
Expand description

A visitor for routing a raw JSON request to an appropriate handler function.

Most requests are read-only and async and are handled on the threadpool (on method).

Some read-only requests are latency sensitive, and are immediately handled on the main loop thread (on_sync). These are typically typing-related requests.

Some requests modify the state, and are run on the main thread to get &mut (on_sync_mut).

Read-only requests are wrapped into catch_unwind – they don’t modify the state, so it’s OK to recover from their failures.

Fields§

§req: Option<Request>§global_state: &'a mut GlobalState

Implementations§

Source§

impl RequestDispatcher<'_>

Source

pub(crate) fn on_sync_mut<R>( &mut self, f: fn(&mut GlobalState, R::Params) -> Result<R::Result>, ) -> &mut Self
where R: Request, R::Params: DeserializeOwned + UnwindSafe + Debug, R::Result: Serialize,

Dispatches the request onto the current thread, given full access to mutable global state. Unlike all other methods here, this one isn’t guarded by catch_unwind, so, please, don’t make bugs :-)

Source

pub(crate) fn on_sync<R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, ) -> &mut Self
where R: Request, R::Params: DeserializeOwned + UnwindSafe + Debug, R::Result: Serialize,

Dispatches the request onto the current thread.

Source

pub(crate) fn on<const ALLOW_RETRYING: bool, R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, ) -> &mut Self
where R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,

Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not ready this will return a default constructed R::Result.

Source

pub(crate) fn on_with_vfs_default<R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, default: impl FnOnce() -> R::Result, on_cancelled: fn() -> ResponseError, ) -> &mut Self
where R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize> + 'static,

Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not ready this will return a default constructed R::Result.

Source

pub(crate) fn on_identity<const ALLOW_RETRYING: bool, R, Params>( &mut self, f: fn(GlobalStateSnapshot, Params) -> Result<R::Result>, ) -> &mut Self
where R: Request<Params = Params, Result = Params> + 'static, Params: Serialize + DeserializeOwned + UnwindSafe + Send + Debug,

Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not ready this will return the parameter as is.

Source

pub(crate) fn on_latency_sensitive<const ALLOW_RETRYING: bool, R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, ) -> &mut Self
where R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,

Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not ready this will return a default constructed R::Result.

Source

pub(crate) fn on_fmt_thread<R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, ) -> &mut Self
where R: Request + 'static, R::Params: DeserializeOwned + UnwindSafe + Send + Debug, R::Result: Serialize,

Formatting requests should never block on waiting a for task thread to open up, editors will wait on the response and a late formatting update might mess with the document and user. We can’t run this on the main thread though as we invoke rustfmt which may take arbitrary time to complete!

Source

pub(crate) fn finish(&mut self)

Source

fn on_with_thread_intent<const RUSTFMT: bool, const ALLOW_RETRYING: bool, R>( &mut self, intent: ThreadIntent, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, on_cancelled: fn() -> ResponseError, ) -> &mut Self
where R: Request + 'static, R::Params: DeserializeOwned + UnwindSafe + Send + Debug, R::Result: Serialize,

Source

fn parse<R>(&mut self) -> Option<(Request, R::Params, String)>
where R: Request, R::Params: DeserializeOwned + Debug,

Source

fn content_modified_error() -> ResponseError

Auto Trait Implementations§

§

impl<'a> Freeze for RequestDispatcher<'a>

§

impl<'a> !RefUnwindSafe for RequestDispatcher<'a>

§

impl<'a> !Send for RequestDispatcher<'a>

§

impl<'a> !Sync for RequestDispatcher<'a>

§

impl<'a> Unpin for RequestDispatcher<'a>

§

impl<'a> UnsafeUnpin for RequestDispatcher<'a>

§

impl<'a> !UnwindSafe for RequestDispatcher<'a>

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
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,