pub struct Mount(/* private fields */);Expand description
A normalised mount path: absolute, without a trailing slash, without . or ...
Normalisation is idempotent and total — an unacceptable path is refused rather than repaired, because a mount is intent and a guess at intent is how a surface ends up somewhere nobody meant.
use majordomus_cli::web::model::Mount;
assert_eq!(Mount::parse("/tests/").unwrap().as_str(), "/tests");
assert_eq!(Mount::parse("/").unwrap().as_str(), "/");
assert_eq!(Mount::parse("tests").unwrap().as_str(), "/tests");
assert!(Mount::parse("/a/../b").is_err());
assert!(Mount::parse("//a").is_err());Implementations§
Source§impl Mount
impl Mount
Sourcepub fn parse(raw: &str) -> Result<Self, String>
pub fn parse(raw: &str) -> Result<Self, String>
Parse and normalise a mount path, or say why it is not one.
use majordomus_cli::web::model::Mount;
// normalisation is idempotent
let once = Mount::parse("/benchmarks/").unwrap();
let twice = Mount::parse(once.as_str()).unwrap();
assert_eq!(once, twice);Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Is this the root mount, the one surface allowed to answer what nothing else claims?
Sourcepub fn prefix(&self) -> String
pub fn prefix(&self) -> String
The prefix a request path must carry to belong to this mount, with its trailing slash.
use majordomus_cli::web::model::Mount;
assert_eq!(Mount::parse("/tests").unwrap().prefix(), "/tests/");
assert_eq!(Mount::root().prefix(), "/");Sourcepub fn owns(&self, path: &str) -> bool
pub fn owns(&self, path: &str) -> bool
Does this mount own path — the mount itself, or anything below it?
use majordomus_cli::web::model::Mount;
let m = Mount::parse("/tests").unwrap();
assert!(m.owns("/tests"));
assert!(m.owns("/tests/"));
assert!(m.owns("/tests/coverage/index.html"));
assert!(!m.owns("/tests-of-something"));
assert!(Mount::root().owns("/anything"));Sourcepub fn contains(&self, other: &Mount) -> bool
pub fn contains(&self, other: &Mount) -> bool
Is other inside this mount? The root contains everything, itself included.
use majordomus_cli::web::model::Mount;
let outer = Mount::parse("/tests").unwrap();
let inner = Mount::parse("/tests/coverage").unwrap();
assert!(outer.contains(&inner));
assert!(!inner.contains(&outer));Sourcepub fn relative(&self) -> String
pub fn relative(&self) -> String
The path under a destination root this mount composes into, relative and without a leading slash: the root mount composes into the destination itself.
use majordomus_cli::web::model::Mount;
assert_eq!(Mount::parse("/tests").unwrap().relative(), "tests");
assert_eq!(Mount::root().relative(), "");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Mount
impl<'de> Deserialize<'de> for Mount
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 Mount
Source§impl JsonSchema for Mount
impl JsonSchema for Mount
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 moreSource§impl Ord for Mount
impl Ord for Mount
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Mount
impl PartialOrd for Mount
impl StructuralPartialEq for Mount
Auto Trait Implementations§
impl Freeze for Mount
impl RefUnwindSafe for Mount
impl Send for Mount
impl Sync for Mount
impl Unpin for Mount
impl UnsafeUnpin for Mount
impl UnwindSafe for Mount
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.