pub struct Library {
pub folders: HashMap<String, Folder>,
pub notes: HashMap<String, Note>,
pub resources: HashMap<String, Resource>,
pub tags: HashMap<String, Tag>,
pub note_tags: Vec<NoteTag>,
/* private fields */
}Fields§
§folders: HashMap<String, Folder>§notes: HashMap<String, Note>§resources: HashMap<String, Resource>Implementations§
Source§impl Library
impl Library
Sourcepub fn from_contents(contents: Vec<String>) -> (Library, BuildStats)
pub fn from_contents(contents: Vec<String>) -> (Library, BuildStats)
把一批原始 .md 内容解析、分类、建索引为 Library,返回类型计数 + 解析错误数。 拉取(并行/缓存)由调用方负责;这里只做纯解析与索引,便于编译到 WASM。
Sourcepub fn note_count(&self, folder_id: &str) -> usize
pub fn note_count(&self, folder_id: &str) -> usize
某笔记本(含根 “”)直属笔记数。
Sourcepub fn child_folder_ids_sorted(&self, parent_id: &str) -> Vec<String>
pub fn child_folder_ids_sorted(&self, parent_id: &str) -> Vec<String>
子笔记本,按标题排序。
Sourcepub fn notes_in_folder_sorted(&self, folder_id: &str) -> Vec<&Note>
pub fn notes_in_folder_sorted(&self, folder_id: &str) -> Vec<&Note>
某笔记本下的笔记,按更新时间倒序。
Sourcepub fn tag_note_count(&self, tag_id: &str) -> usize
pub fn tag_note_count(&self, tag_id: &str) -> usize
某标签下仍存在的笔记数。
全部标签,按标题(不区分大小写)排序。
Sourcepub fn notes_with_tag(&self, tag_id: &str) -> Vec<&Note>
pub fn notes_with_tag(&self, tag_id: &str) -> Vec<&Note>
打了某标签的笔记,按更新时间倒序(与笔记本视图一致)。
Sourcepub fn tag_id_by_title(&self, title: &str) -> Option<String>
pub fn tag_id_by_title(&self, title: &str) -> Option<String>
按标题查已有标签 id(trim + 不区分大小写,对齐 Joplin Tag.loadByTitle 语义)。
多个同名时取 id 最小者以保证确定性(Joplin 用 created_time,本模型不存该字段)。
Sourcepub fn note_has_tag(&self, note_id: &str, tag_id: &str) -> bool
pub fn note_has_tag(&self, note_id: &str, tag_id: &str) -> bool
笔记是否已打某标签(据关联表;用于新增去重、对齐 Joplin addNote 的 hasNote 短路)。
Sourcepub fn note_tag_ids_for(&self, note_id: &str, tag_id: &str) -> Vec<String>
pub fn note_tag_ids_for(&self, note_id: &str, tag_id: &str) -> Vec<String>
(note,tag) 对应的全部 note_tag 条目 id(Joplin removeNote 删全部匹配)。
某笔记的标签,按标题(不区分大小写)排序。
pub fn note(&self, id: &str) -> Option<&Note>
pub fn resource(&self, id: &str) -> Option<&Resource>
Sourcepub fn upsert_note(&mut self, content: &str) -> Result<String>
pub fn upsert_note(&mut self, content: &str) -> Result<String>
新增或更新一篇笔记(写回成功后同步内存)。返回笔记 id。
Sourcepub fn upsert_folder(&mut self, content: &str) -> Result<String>
pub fn upsert_folder(&mut self, content: &str) -> Result<String>
新增或更新一个笔记本(写回成功后同步内存)。返回笔记本 id。
Sourcepub fn is_self_or_descendant(&self, root: &str, candidate: &str) -> bool
pub fn is_self_or_descendant(&self, root: &str, candidate: &str) -> bool
candidate 是否就是 root 本身、或位于 root 子树之下。
用于移动笔记本时防止把笔记本移进它自己或其后代(成环)。
Sourcepub fn subtree_folder_ids(&self, root: &str) -> Vec<String>
pub fn subtree_folder_ids(&self, root: &str) -> Vec<String>
某笔记本自身 + 其所有后代笔记本 id(BFS)。root 不存在则返回空。
用于访问控制的黑白名单按子树展开(server::auth::AuthState::scope)。
Sourcepub fn upsert_resource(&mut self, content: &str) -> Result<String>
pub fn upsert_resource(&mut self, content: &str) -> Result<String>
新增或更新一个资源(上传成功后同步内存,使 /api/resources 能拿到 mime)。返回资源 id。
Sourcepub fn remove_note(&mut self, id: &str)
pub fn remove_note(&mut self, id: &str)
删除一篇笔记(写回成功后同步内存)。
Sourcepub fn upsert_tag(&mut self, content: &str) -> Result<String>
pub fn upsert_tag(&mut self, content: &str) -> Result<String>
新增或更新一个标签(写回成功后同步内存)。返回标签 id。
Sourcepub fn upsert_note_tag(&mut self, content: &str) -> Result<NoteTag>
pub fn upsert_note_tag(&mut self, content: &str) -> Result<NoteTag>
新增一个 note_tag 关联(写回成功后同步内存)。按 id 去重后重建标签成员索引。
Sourcepub fn remove_note_tag(&mut self, id: &str)
pub fn remove_note_tag(&mut self, id: &str)
删除一个 note_tag 关联(按条目 id;写回成功后同步内存)。
Sourcepub fn remove_resource(&mut self, id: &str)
pub fn remove_resource(&mut self, id: &str)
删除一个资源(写回成功后同步内存)。
Sourcepub fn resource_usage(&self) -> HashMap<String, usize>
pub fn resource_usage(&self) -> HashMap<String, usize>
每个资源被多少篇笔记引用(扫描所有笔记正文里的 :/<id>)。
未出现在结果中的资源即为无人引用的“孤儿”。