pub struct PathTemplate { /* private fields */ }Expand description
A parsed path template such as /users/{id}/posts/{postId}.
Two templates that differ only in variable name are the same path as far
as OpenAPI is concerned, so declaring both is invalid.
normalized exists to make that comparison
cheap.
Implementations§
Source§impl PathTemplate
impl PathTemplate
Sourcepub fn parse(raw: impl Into<String>) -> Result<Self, InvalidPathTemplate>
pub fn parse(raw: impl Into<String>) -> Result<Self, InvalidPathTemplate>
Parses a path template.
Literal segments are checked against the path grammar; variable names are not, because the grammar admits every character except a brace there. A name that Kynos’s router cannot match — a catch-all, say — is still a legal OpenAPI template, and this type has to be able to hold one so that an externally authored description round-trips. That narrower contract is enforced where routes are registered.
§Errors
Returns InvalidPathTemplate when the template does not start with
/, has unbalanced or empty braces, repeats a variable, carries a query
string or fragment, or holds a character the path grammar does not allow
outside a {} expression.
Sourcepub fn normalized(&self) -> String
pub fn normalized(&self) -> String
The template with every variable name replaced by {}.
Two templates are the same path if and only if their normalized forms are equal.
Sourcepub fn with_prefix(&self, prefix: &str) -> Result<Self, InvalidPathTemplate>
pub fn with_prefix(&self, prefix: &str) -> Result<Self, InvalidPathTemplate>
Concatenates a prefix onto this template, as nesting does.
§Errors
Returns InvalidPathTemplate when the result is not a valid template,
which is how a prefix that repeats one of this template’s variables is
caught.
Trait Implementations§
Source§impl Clone for PathTemplate
impl Clone for PathTemplate
Source§impl Debug for PathTemplate
impl Debug for PathTemplate
Source§impl<'de> Deserialize<'de> for PathTemplate
impl<'de> Deserialize<'de> for PathTemplate
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>,
Source§impl Display for PathTemplate
impl Display for PathTemplate
impl Eq for PathTemplate
Source§impl From<PathTemplate> for String
impl From<PathTemplate> for String
Source§fn from(template: PathTemplate) -> Self
fn from(template: PathTemplate) -> Self
Source§impl FromStr for PathTemplate
impl FromStr for PathTemplate
Source§impl Hash for PathTemplate
impl Hash for PathTemplate
Source§impl PartialEq for PathTemplate
impl PartialEq for PathTemplate
Source§impl Serialize for PathTemplate
impl Serialize for PathTemplate
impl StructuralPartialEq for PathTemplate
Auto Trait Implementations§
impl Freeze for PathTemplate
impl RefUnwindSafe for PathTemplate
impl Send for PathTemplate
impl Sync for PathTemplate
impl Unpin for PathTemplate
impl UnsafeUnpin for PathTemplate
impl UnwindSafe for PathTemplate
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
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>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.