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 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 upsert_resource(&mut self, content: &str) -> Result<String>

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

Source

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

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

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.