pub struct Topology {
pub surfaces: Vec<Surface>,
}Expand description
Every surface this repository exposes, resolved together.
The order is by mount, most specific first, then by id: the order a router must consult them in, computed rather than left to whoever inserted a route last.
Fields§
§surfaces: Vec<Surface>The resolved surfaces, in route-precedence order.
Implementations§
Source§impl Topology
impl Topology
Sourcepub fn new(surfaces: Vec<Surface>) -> Self
pub fn new(surfaces: Vec<Surface>) -> Self
Sort surfaces into route-precedence order and hold them.
Precedence is depth first — a longer mount wins over a shorter one, so the root application is consulted last — and identity breaks ties, so the order never depends on discovery order, filesystem order or a hash map.
use majordomus_cli::web::model::*;
let t = Topology::new(vec![s("app", "/"), s("tests", "/tests")]);
assert_eq!(t.surfaces[0].id, "tests"); // the specific one is consulted first
assert_eq!(t.surfaces[1].id, "app");
// the root is last whatever it is compared with: `owner()` rests on this, and the
// root's own slash must never be counted as depth
let deep = Topology::new(vec![s("api", "/api/v1"), s("root", "/"), s("docs", "/docs")]);
assert_eq!(deep.ids(), vec!["api", "docs", "root"]);Sourcepub fn owner(&self, path: &str) -> Option<&Surface>
pub fn owner(&self, path: &str) -> Option<&Surface>
The surface that owns a request path, or none when nothing does.
use majordomus_cli::web::model::*;
let t = Topology::new(vec![s("app", "/"), s("tests", "/tests")]);
assert_eq!(t.owner("/tests/index.html").unwrap().id, "tests");
assert_eq!(t.owner("/anything-else").unwrap().id, "app");Sourcepub fn select(&self, only: &[String], exclude: &[String]) -> Topology
pub fn select(&self, only: &[String], exclude: &[String]) -> Topology
The topology narrowed to a selection: only when it is not empty, minus exclude.
Selection is by discovered id and nothing else, so a surface that did not exist when this code was written is selectable the day it is discovered.
Sourcepub fn served(&self, runtime: Runtime) -> Topology
pub fn served(&self, runtime: Runtime) -> Topology
The topology as a process with these runtime capabilities serves it.
One resolution, two worlds: a surface that is only published (the site as it is deployed) is not served, and a surface whose feature this process does not have is not there at all. Both narrowings are filters over the same value, so nothing can be served that was not discovered.
use majordomus_cli::web::discover::{self, Runtime};
let all = discover::native(Runtime::full());
let none = majordomus_cli::web::Topology::new(all).served(Runtime::default());
assert!(!none.ids().contains(&"mcp"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Topology
impl<'de> Deserialize<'de> for Topology
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Topology
Source§impl JsonSchema for Topology
impl JsonSchema for Topology
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for Topology
Auto Trait Implementations§
impl Freeze for Topology
impl RefUnwindSafe for Topology
impl Send for Topology
impl Sync for Topology
impl Unpin for Topology
impl UnsafeUnpin for Topology
impl UnwindSafe for Topology
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.