use indextree::NodeId as IndexTreeNodeId;
use serde::{Deserialize, Serialize};
use std::fmt;
use super::reference::NodeReference;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NodeId(pub IndexTreeNodeId);
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "NodeId({:?})", self.0)
}
}
impl Serialize for NodeId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.serialize(serializer)
}
}
impl<'de> Deserialize<'de> for NodeId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let id = IndexTreeNodeId::deserialize(deserializer)?;
Ok(NodeId(id))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TreeNode {
pub title: String,
#[serde(default)]
pub structure: String,
#[serde(default)]
pub content: String,
#[serde(default)]
pub summary: String,
#[serde(default)]
pub depth: usize,
#[serde(default)]
pub start_index: usize,
#[serde(default)]
pub end_index: usize,
pub start_page: Option<usize>,
pub end_page: Option<usize>,
pub node_id: Option<String>,
pub physical_index: Option<String>,
pub token_count: Option<usize>,
#[serde(default)]
pub references: Vec<NodeReference>,
}
impl Default for TreeNode {
fn default() -> Self {
Self {
title: String::new(),
structure: String::new(),
content: String::new(),
summary: String::new(),
depth: 0,
start_index: 1,
end_index: 1,
start_page: None,
end_page: None,
node_id: None,
physical_index: None,
token_count: None,
references: Vec::new(),
}
}
}