Skip to main content

Library

Struct Library 

Source
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>§tags: HashMap<String, Tag>§note_tags: Vec<NoteTag>

Implementations§

Source§

impl Library

Source

pub fn from_contents(contents: Vec<String>) -> (Library, BuildStats)

把一批原始 .md 内容解析、分类、建索引为 Library,返回类型计数 + 解析错误数。 拉取(并行/缓存)由调用方负责;这里只做纯解析与索引,便于编译到 WASM。

Source

pub fn note_count(&self, folder_id: &str) -> usize

某笔记本(含根 “”)直属笔记数。

Source

pub fn child_folder_ids_sorted(&self, parent_id: &str) -> Vec<String>

子笔记本,按标题排序。

Source

pub fn notes_in_folder_sorted(&self, folder_id: &str) -> Vec<&Note>

某笔记本下的笔记,按更新时间倒序。

Source

pub fn tag_note_count(&self, tag_id: &str) -> usize

某标签下仍存在的笔记数。

Source

pub fn tags_sorted(&self) -> Vec<&Tag>

全部标签,按标题(不区分大小写)排序。

Source

pub fn notes_with_tag(&self, tag_id: &str) -> Vec<&Note>

打了某标签的笔记,按更新时间倒序(与笔记本视图一致)。

Source

pub fn tag_id_by_title(&self, title: &str) -> Option<String>

按标题查已有标签 id(trim + 不区分大小写,对齐 Joplin Tag.loadByTitle 语义)。 多个同名时取 id 最小者以保证确定性(Joplin 用 created_time,本模型不存该字段)。

Source

pub fn note_has_tag(&self, note_id: &str, tag_id: &str) -> bool

笔记是否已打某标签(据关联表;用于新增去重、对齐 Joplin addNote 的 hasNote 短路)。

Source

pub fn note_tag_ids_for(&self, note_id: &str, tag_id: &str) -> Vec<String>

(note,tag) 对应的全部 note_tag 条目 id(Joplin removeNote 删全部匹配)。

Source

pub fn tags_of_note(&self, note_id: &str) -> Vec<&Tag>

某笔记的标签,按标题(不区分大小写)排序。

Source

pub fn note(&self, id: &str) -> Option<&Note>

Source

pub fn resource(&self, id: &str) -> Option<&Resource>

Source

pub fn search(&self, query: &str) -> Vec<&Note>

简单全文搜索:标题/正文不区分大小写包含。按更新时间倒序,限制 200 条。

Source

pub fn note_raw(&self, id: &str) -> Option<&str>

笔记的原始 .md 内容(保存时用于保留元数据)。

Source

pub fn upsert_note(&mut self, content: &str) -> Result<String>

新增或更新一篇笔记(写回成功后同步内存)。返回笔记 id。

Source

pub fn upsert_folder(&mut self, content: &str) -> Result<String>

新增或更新一个笔记本(写回成功后同步内存)。返回笔记本 id。

Source

pub fn is_self_or_descendant(&self, root: &str, candidate: &str) -> bool

candidate 是否就是 root 本身、或位于 root 子树之下。 用于移动笔记本时防止把笔记本移进它自己或其后代(成环)。

Source

pub fn subtree_folder_ids(&self, root: &str) -> Vec<String>

某笔记本自身 + 其所有后代笔记本 id(BFS)。root 不存在则返回空。 用于访问控制的黑白名单按子树展开(server::auth::AuthState::scope)。

Source

pub fn upsert_resource(&mut self, content: &str) -> Result<String>

新增或更新一个资源(上传成功后同步内存,使 /api/resources 能拿到 mime)。返回资源 id。

Source

pub fn remove_note(&mut self, id: &str)

删除一篇笔记(写回成功后同步内存)。

Source

pub fn upsert_tag(&mut self, content: &str) -> Result<String>

新增或更新一个标签(写回成功后同步内存)。返回标签 id。

Source

pub fn upsert_note_tag(&mut self, content: &str) -> Result<NoteTag>

新增一个 note_tag 关联(写回成功后同步内存)。按 id 去重后重建标签成员索引。

Source

pub fn remove_note_tag(&mut self, id: &str)

删除一个 note_tag 关联(按条目 id;写回成功后同步内存)。

Source

pub fn remove_resource(&mut self, id: &str)

删除一个资源(写回成功后同步内存)。

Source

pub fn resource_usage(&self) -> HashMap<String, usize>

每个资源被多少篇笔记引用(扫描所有笔记正文里的 :/<id>)。 未出现在结果中的资源即为无人引用的“孤儿”。

Trait Implementations§

Source§

impl Default for Library

Source§

fn default() -> Library

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.