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