Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

The data folder where tasks are stored.

Implementations§

Source§

impl Store

Source

pub fn open() -> Result<Self>

The nearest .brain/ in the current directory or above it, so each project’s repository keeps its own; else the central brain ($KANBRAIN_DIR, else the platform data dir, e.g. ~/.local/share/kanbrain).

Source

pub fn open_named(name: Option<&str>) -> Result<Self>

The brain of the project registered as name (central for the central one), from anywhere; without a name, the one Store::open finds.

Source

pub fn project(&self) -> Option<String>

The project’s name: the one on its card (project.md), else the folder holding .brain/; None for the central brain.

Source

pub fn at(dir: impl Into<PathBuf>) -> Result<Self>

A store in dir, created if missing.

Source

pub fn lock(&self) -> Result<BrainLock>

Takes this brain’s write lock, waiting while another program holds it, until the returned guard is dropped. Each kb that changes entries reads every file, changes some and writes them back: an agent running several at once (one per subagent) would otherwise have the last one write over the others’ changes, or two adds take the same id. The lock is released when the process ends, however it ends.

The lock file lives in the user’s cache folder, named after the brain’s folder, so .brain/ (often committed) gets no extra file. Taking it again on a thread that holds it gets a guard that does nothing: the app holds every brain’s while it acts, and managing projects takes some of them itself.

Source

pub fn record(&self)

Starts recording the files written or deleted from now on, so they can be put back (see undo).

Source

pub fn recorded(&self) -> Vec<Change>

Stops recording, and returns what was recorded, with what each file holds now.

Source

pub fn dir(&self) -> &Path

The data folder.

Source

pub fn reports_dir(&self) -> PathBuf

Where report exports are written.

Source

pub fn load(&self) -> Result<(Vec<Task>, Vec<String>)>

Returns the parsed tasks plus a warning for every file that could not be read.

Source

pub fn save(&self, task: &mut Task) -> Result<()>

Writes atomically and renames the file when the title (slug) changed.

Source

pub fn delete(&self, task: &Task) -> Result<()>

Removes the task’s file. Refuses anything outside the data folder.

Source

pub fn last_id(&self) -> u32

The highest id given so far, as last-id keeps it; 0 when it’s missing (a folder from an older version) or unreadable, and then the entries’ own ids are all there is to go by.

Source

pub fn save_last_id(&self, id: u32) -> Result<()>

Writes last-id.

Source

pub fn load_tag_colors(&self) -> Result<TagColors>

Reads tags.md; no file means no colors assigned yet.

Source

pub fn save_tag_colors(&self, colors: &TagColors) -> Result<()>

Writes tags.md.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Sync for Store

§

impl Send for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.