Simpler Resource

This commit is contained in:
Adrian Heine 2017-05-10 10:54:15 +02:00
parent 8e848fc104
commit 7b0575da1b
10 changed files with 31 additions and 49 deletions

View file

@ -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
}
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 }
pub fn get_type(&self) -> &str {
&self.0
}
pub fn get_value(&self) -> &str {
&self.1
}
}