2021-12-14 19:33:17 +01:00
|
|
|
use crate::Path;
|
|
|
|
|
|
|
|
// TODO: this trait is necessary, document it
|
|
|
|
// see impl Resource for ServiceRequest
|
2022-01-05 05:34:13 +01:00
|
|
|
pub trait Resource {
|
|
|
|
/// Type of resource's path returned in `resource_path`.
|
|
|
|
type Path: ResourcePath;
|
|
|
|
|
|
|
|
fn resource_path(&mut self) -> &mut Path<Self::Path>;
|
2021-12-14 19:33:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ResourcePath {
|
|
|
|
fn path(&self) -> &str;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ResourcePath for String {
|
|
|
|
fn path(&self) -> &str {
|
|
|
|
self.as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ResourcePath for &'a str {
|
|
|
|
fn path(&self) -> &str {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ResourcePath for bytestring::ByteString {
|
|
|
|
fn path(&self) -> &str {
|
|
|
|
&*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "http")]
|
|
|
|
impl ResourcePath for http::Uri {
|
|
|
|
fn path(&self) -> &str {
|
|
|
|
self.path()
|
|
|
|
}
|
|
|
|
}
|