Skip to main content

Router

Struct Router 

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

Routes requests to the surfaces this process serves. Cheap to clone: every worker thread holds one, and the resolution behind it is shared.

Implementations§

Source§

impl Router

Source

pub fn new(live: impl IntoLive, version: &'static str) -> Self

A router over a view of the repository, without /mcp and without the Cockpit.

live is either the Live the shared server follows the repository with or a plain Arc<Context>, which becomes a pinned view: a one-shot process and a benchmark have nothing to follow and pay nothing to prove it.

Source

pub fn with_cockpit(self, share_dir: Option<&Path>) -> Self

The same router, serving the Cockpit’s pages with its assets read from share_dir.

Source

pub fn with_ui(self, share_dir: Option<&Path>) -> Self

The same router, serving the UI’s pages (ADR 0135) with its assets read from share_dir. Without a distribution the screens are still complete HTML, unstyled; either way the UI becomes one of the surfaces the topology says this process serves.

let router = router.with_ui(None);
let served = router.served().expect("a topology that resolves");
assert!(served.topology().surfaces.iter().any(|s| s.id == majordomus_cli::ui::SURFACE));
Source

pub fn with_mcp(self, endpoint: Arc<McpEndpoint>) -> Self

The same router, serving MCP over HTTP through endpoint.

Source

pub fn served(&self) -> Result<ServedRef, Error>

The surfaces this router serves, for a caller that wants to describe them: the server’s startup line, and the tests.

The answer is the resolution, not a fresh discovery — a router that could not resolve its topology never answered a request either, and says the same thing here that it says to a client.

Source

pub fn websocket(&self, req: &Request) -> Option<Result<Accepted, Response>>

Does this request open the live channel, and may it?

The server asks before it reads a body or writes a response, because an upgrade is the one thing a router cannot answer: it hands the socket over. None means the request is not for the live channel at all and is routed normally.

Source

pub fn handle(&self, req: &Request) -> Response

Answer one request: the surface that owns its path, or nothing.

A request that carries an Origin header came from a page in a browser. A browser cannot read a cross-origin response without the headers this server never sends, so a read is already contained; a request that changes something is not, and one from another origin is refused before it reaches a handler. A client that is not a browser sends no Origin and is unaffected.

Trait Implementations§

Source§

impl Clone for Router

Source§

fn clone(&self) -> Router

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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<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