|
@ -1,33 +1,15 @@ |
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
|
|
|
|
pub trait Resource {
|
|
|
|
|
|
fn get_type(&self) -> &str;
|
|
|
|
|
|
fn get_value(&self) -> &str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct UserResource<'a> {
|
|
|
|
|
|
pub name: &'a str
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Resource for UserResource<'a> {
|
|
|
|
|
|
fn get_type(&self) -> &str { "user" }
|
|
|
|
|
|
fn get_value(&self) -> &str { self.name }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct DirResource<'a> {
|
|
|
|
|
|
pub path: Cow<'a, str>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Resource for DirResource<'a> {
|
|
|
|
|
|
fn get_type(&self) -> &str { "dir" }
|
|
|
|
|
|
fn get_value(&self) -> &str { &*self.path }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct FileResource<'a> {
|
|
|
|
|
|
pub path: Cow<'a, str>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Resource for FileResource<'a> {
|
|
|
|
|
|
fn get_type(&self) -> &str { "file" }
|
|
|
|
|
|
fn get_value(&self) -> &str { &*self.path }
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
|
|
|
|
|
pub struct Resource(pub String, pub String);
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Resource {
|
|
|
|
|
|
pub fn new<A: Into<String>, B: Into<String>>(rtype: A, value: B) -> Self {
|
|
|
|
|
|
Resource(rtype.into(), value.into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_type(&self) -> &str {
|
|
|
|
|
|
&self.0
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn get_value(&self) -> &str {
|
|
|
|
|
|
&self.1
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|