Skip to main content

Crate nb_api

Crate nb_api 

Source
Expand description

Typed Rust interface to the nb note-taking CLI.

Handles notebook qualification, escaping, and output parsing. Wraps the nb CLI as a subprocess, providing async methods for all note-taking operations.

§Concurrency (0.3.0)

Notebook-scoped reads and Transaction::commit are serialized by a process-shared, in-process gate registry keyed by the realpath of the notebook Git common directory. Independently constructed NbClient values that resolve to the same repository share one gate. Cross-process index.lock wait is deferred.

Re-exports§

pub use fingerprint::Fingerprint;
pub use fingerprint::fingerprint as compute_fingerprint;
pub use parser::BodyFragments;
pub use parser::DocumentKind;
pub use parser::NoteDocument;
pub use parser::ParseContext;
pub use parser::SUPPORTED_DOCUMENT_EXTENSIONS;
pub use parser::TagsIter;
pub use parser::TagsStrIter;
pub use parser::TodoState;
pub use parser::parse;

Modules§

fingerprint
Fingerprint scheme for NoteDocument.
parser
Structural parser for nb notes, todos, and bookmarks.

Structs§

BodyFragment
One body fragment exposed by structured show.
Classify
Classify record: kind, path, and shadow-aware selector for one id, without reading content beyond classification.
CommitOutcome
Structured result of crate::Transaction::commit.
Config
Configuration for constructing an NbClient.
IoError
Serializable snapshot of a std::io::Error chain.
LineAnchor
Versioned body-line authenticity token: b3l1:<32 lowercase hex>.
LineRef
Number + anchor reference to a body line.
ListEntry
One typed list entry: shadow-aware canonical selector built at the source (numeric form only when it re-resolves to the same entity, else exact-path form).
NbClient
Client for invoking nb commands.
NoteLine
One enumerated body line (line text without terminator).
NoteLineHit
One search hit within a body line.
OpOutcome
Outcome of one plan op after a successful commit.
SearchNoteLines
Result of search_note_lines.
ShowNote
Structured show_note result.
ShowNoteLines
Windowed body-line listing with a document-level EOL declaration.
TodoSummary
Todo summary with explicit open/closed state and shadow-aware canonical id. Minimal six fields, nothing more.
Transaction
In-memory plan bound to one notebook. Drop discards; no begin/rollback.

Enums§

BoundaryAt
Virtual body boundaries (^ / $).
EntityKind
Entity kind for typed list and classify surfaces.
IoErrorKind
Discriminator for the std::io::ErrorKind taxonomy, lifted into a serializable form. Marked #[non_exhaustive] so future versions can add new kinds without breaking downstream match arms that include a default branch.
KindSet
Accepted-kinds set for an operation, used by NbError::WrongKind. File is any non-folder entity, Document the text kinds (Note | Todo | Bookmark), Todo only todos, Folder only folders.
LineEdit
One line-oriented edit in an edit_note_lines batch.
LineEol
Document-level end-of-line marker.
LinePosition
Insert position relative to a line or body boundary.
NbError
Errors raised by nb-api operations.
NoteTarget
Address an existing note by selector or notebook-relative path.
Occurrence
Substring occurrence selector.
ParseErrorKind
Narrow refusal contract for the structural parser.
SearchMode
Matching mode for nb search query terms.
TaskStatus
Status filter for nb tasks.

Functions§

derive_git_notebook_name
Derive the notebook name from the current Git repository.
git_rev_parse
Run git rev-parse with the given arguments and return the output as a path.
leaked_git_names
Returns the names of every environment variable in the current process whose name starts with GIT_. Exposed so other call sites (a future std::process::Command variant in git_env, or any caller that wants the list without the scrub) share one enumeration policy.
scrub_git_env
Removes every environment variable whose name starts with GIT_ from the given tokio Command’s environment. The spawned process inherits every other variable from the parent (PATH, HOME, LANG, …), just not the ones that redirect Git’s view of the repository.
scrub_git_env_std
Synchronous-Command variant of scrub_git_env. nb-api uses tokio::process::Command for every nb invocation, but git_rev_parse (the only direct git spawn) uses std::process::Command. Both spawn sites must be scrubbed; if a future helper spawns git synchronously, use this overload.