Skip to main content

eureka_mmanager/files_dirs/messages/modify/
modify_chapters_path.rs

1use crate::files_dirs::DirsOptions;
2use actix::prelude::*;
3use std::{fmt::Debug, path::Path};
4
5#[derive(Debug, Message)]
6#[rtype(result = "()")]
7pub struct ModifyChaptersDirMessage<T>(pub T)
8where
9    T: AsRef<Path> + Debug;
10
11impl<T> Clone for ModifyChaptersDirMessage<T>
12where
13    T: Clone + Debug + AsRef<Path>,
14{
15    fn clone(&self) -> Self {
16        Self(self.0.clone())
17    }
18}
19
20impl<T> AsRef<Path> for ModifyChaptersDirMessage<T>
21where
22    T: AsRef<Path> + Debug,
23{
24    fn as_ref(&self) -> &Path {
25        self.0.as_ref()
26    }
27}
28
29impl<T> From<T> for ModifyChaptersDirMessage<T>
30where
31    T: AsRef<Path> + Debug,
32{
33    fn from(value: T) -> Self {
34        Self(value)
35    }
36}
37
38impl<T> Handler<ModifyChaptersDirMessage<T>> for DirsOptions
39where
40    T: AsRef<Path> + Debug,
41{
42    type Result = ();
43    fn handle(
44        &mut self,
45        msg: ModifyChaptersDirMessage<T>,
46        _ctx: &mut Self::Context,
47    ) -> Self::Result {
48        self.chapters = msg.as_ref().to_path_buf();
49        if let Err(e) = self.verify_and_init() {
50            log::error!("{e}");
51        }
52    }
53}