Skip to content

Commit

Permalink
temp: keep definitions and impls together
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and rami3l committed Apr 9, 2024
1 parent 1196554 commit c6cbab6
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions src/dist/temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ pub(crate) enum CreatingError {
}

#[derive(Debug)]
pub enum Notification<'a> {
CreatingRoot(&'a Path),
CreatingFile(&'a Path),
CreatingDirectory(&'a Path),
FileDeletion(&'a Path, io::Result<()>),
DirectoryDeletion(&'a Path, io::Result<()>),
pub(crate) struct Dir<'a> {
cfg: &'a Cfg,
path: PathBuf,
}

pub struct Cfg {
root_directory: PathBuf,
pub dist_server: String,
notify_handler: Box<dyn Fn(Notification<'_>)>,
impl<'a> ops::Deref for Dir<'a> {
type Target = Path;

fn deref(&self) -> &Path {
self.path.as_path()
}
}

#[derive(Debug)]
pub(crate) struct Dir<'a> {
cfg: &'a Cfg,
path: PathBuf,
impl<'a> Drop for Dir<'a> {
fn drop(&mut self) {
if raw::is_directory(&self.path) {
let n = Notification::DirectoryDeletion(
&self.path,
remove_dir_all::remove_dir_all(&self.path),
);
(self.cfg.notify_handler)(n);
}
}
}

#[derive(Debug)]
Expand All @@ -48,6 +53,32 @@ pub struct File<'a> {
path: PathBuf,
}

impl<'a> ops::Deref for File<'a> {
type Target = Path;

fn deref(&self) -> &Path {
self.path.as_path()
}
}

impl<'a> Drop for File<'a> {
fn drop(&mut self) {
if raw::is_file(&self.path) {
let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path));
(self.cfg.notify_handler)(n);
}
}
}

#[derive(Debug)]
pub enum Notification<'a> {
CreatingRoot(&'a Path),
CreatingFile(&'a Path),
CreatingDirectory(&'a Path),
FileDeletion(&'a Path, io::Result<()>),
DirectoryDeletion(&'a Path, io::Result<()>),
}

impl<'a> Notification<'a> {
pub(crate) fn level(&self) -> NotificationLevel {
use self::Notification::*;
Expand Down Expand Up @@ -89,6 +120,12 @@ impl<'a> Display for Notification<'a> {
}
}

pub struct Cfg {
root_directory: PathBuf,
pub dist_server: String,
notify_handler: Box<dyn Fn(Notification<'_>)>,
}

impl Cfg {
pub fn new(
root_directory: PathBuf,
Expand Down Expand Up @@ -170,40 +207,3 @@ impl fmt::Debug for Cfg {
.finish()
}
}

impl<'a> ops::Deref for Dir<'a> {
type Target = Path;

fn deref(&self) -> &Path {
self.path.as_path()
}
}

impl<'a> ops::Deref for File<'a> {
type Target = Path;

fn deref(&self) -> &Path {
self.path.as_path()
}
}

impl<'a> Drop for Dir<'a> {
fn drop(&mut self) {
if raw::is_directory(&self.path) {
let n = Notification::DirectoryDeletion(
&self.path,
remove_dir_all::remove_dir_all(&self.path),
);
(self.cfg.notify_handler)(n);
}
}
}

impl<'a> Drop for File<'a> {
fn drop(&mut self) {
if raw::is_file(&self.path) {
let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path));
(self.cfg.notify_handler)(n);
}
}
}

0 comments on commit c6cbab6

Please sign in to comment.