2022-02-27 13:16:53 +00:00
|
|
|
use crate::node::Node;
|
2022-09-11 02:32:43 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2022-02-27 13:16:53 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct DirectoryBuffer {
|
|
|
|
pub parent: String,
|
|
|
|
pub nodes: Vec<Node>,
|
|
|
|
pub total: usize,
|
|
|
|
pub focus: usize,
|
2022-09-11 02:32:43 +00:00
|
|
|
|
|
|
|
#[serde(skip)]
|
|
|
|
pub explored_at: DateTime<Utc>,
|
2022-02-27 13:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DirectoryBuffer {
|
|
|
|
pub fn new(parent: String, nodes: Vec<Node>, focus: usize) -> Self {
|
|
|
|
let total = nodes.len();
|
|
|
|
Self {
|
|
|
|
parent,
|
|
|
|
nodes,
|
|
|
|
total,
|
|
|
|
focus,
|
2022-09-11 02:32:43 +00:00
|
|
|
explored_at: Utc::now(),
|
2022-02-27 13:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn focused_node(&self) -> Option<&Node> {
|
|
|
|
self.nodes.get(self.focus)
|
|
|
|
}
|
|
|
|
}
|