我正在尝试将关于inotify事件和哈希映射表的结构信息放入其中,其中inotify watch id作为键,文件名作为值。
extern crate inotify;
use inotify::INotify;
use std::sync::{Arc, Mutex};
use std::collections::HashMap;
struct Notificator {
inotify: INotify,
watch_service: Arc<Mutex<HashMap<inotify::wrapper::Watch, Arc<String>>>>,
}
impl Notificator {
pub fn new() -> Notificator {
Notificator {
inotify: INotify::init().unwrap(),
watch_service: Arc::new(Mutex::new(HashMap::new())),
}
}
pub fn resolving_events(&mut self) {
{
let mut events = self.check_for_events();
self.events_execution(events);
}
}
fn check_for_events(&mut self) -> &[inotify::wrapper::Event] {
self.inotify.available_events().unwrap()
}
fn events_execution(&self, events: &[inotify::wrapper::Event]) {
for event in events.iter() {
}
}
}
在编译过程中,我遇到了一个错误。
src/main.rs:204:13: 204:17 error: cannot borrow `*self` as immutable because it is also borrowed as mutable [E0502]
src/main.rs:204 self.events_execution(events);
我认为最好的解决方案是以某种方式将Notificator结构中的inotify变量与watch_service分离,但我无法解除self.check_for_events();
,因为我收到了
src/main.rs:203:17: 203:27 error: the trait bound `[inotify::wrapper::Event]: std::marker::Sized` is not satisfied [E0277]
src/main.rs:203 let mut events = *self.check_for_events();
我理解问题的核心:我试图通过
check_for_events
借用引用并将其作为参数传递给需要 self
作为参数的 events_execution
,但是我不知道如何解决它。
self
吗?如果不是,那么不将其作为参数可能会解决你的问题。 - Noctua