Cargo format
This commit is contained in:
parent
9bab810b91
commit
8c0224e983
44 changed files with 1784 additions and 611 deletions
|
|
@ -7,17 +7,26 @@ use std::path::Path;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct Dir<D> where D: AsRef<str> {
|
||||
path: D
|
||||
pub struct Dir<D>
|
||||
where
|
||||
D: AsRef<str>,
|
||||
{
|
||||
path: D,
|
||||
}
|
||||
|
||||
impl<D> Dir<D> where D: AsRef<str> {
|
||||
impl<D> Dir<D>
|
||||
where
|
||||
D: AsRef<str>,
|
||||
{
|
||||
pub fn new(path: D) -> Self {
|
||||
Dir { path }
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> Symbol for Dir<D> where D: AsRef<str> {
|
||||
impl<D> Symbol for Dir<D>
|
||||
where
|
||||
D: AsRef<str>,
|
||||
{
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let metadata = fs::metadata(self.path.as_ref());
|
||||
// Check if dir exists
|
||||
|
|
@ -31,7 +40,10 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> {
|
|||
if metadata.unwrap().is_dir() {
|
||||
Ok(true)
|
||||
} else {
|
||||
Err(Box::new(io::Error::new(io::ErrorKind::AlreadyExists, "Could not create a directory, non-directory file exists")))
|
||||
Err(Box::new(io::Error::new(
|
||||
io::ErrorKind::AlreadyExists,
|
||||
"Could not create a directory, non-directory file exists",
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,27 +53,33 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> {
|
|||
|
||||
fn get_prerequisites(&self) -> Vec<Resource> {
|
||||
if let Some(parent) = Path::new(self.path.as_ref()).parent() {
|
||||
vec![ Resource::new("dir", parent.to_string_lossy()) ]
|
||||
vec![Resource::new("dir", parent.to_string_lossy())]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn provides(&self) -> Option<Vec<Resource>> {
|
||||
Some(vec![ Resource::new("dir", self.path.as_ref()) ])
|
||||
Some(vec![Resource::new("dir", self.path.as_ref())])
|
||||
}
|
||||
|
||||
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
|
||||
Box::new(SymbolAction::new(runner, self))
|
||||
}
|
||||
|
||||
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
|
||||
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Box::new(OwnedSymbolAction::new(runner, *self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> fmt::Display for Dir<D> where D: AsRef<str> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
|
||||
impl<D> fmt::Display for Dir<D>
|
||||
where
|
||||
D: AsRef<str>,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "Dir {}", self.path.as_ref())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue