Skip to main content

Module storage

Module storage 

Source
Expand description

Storage abstraction layer for task persistence.

This module defines the Storage trait and re-exports two built-in implementations:

TypeDescription
JsonStoragePersists tasks to a JSON file in the OS data directory
InMemoryStorageStores tasks in memory — ideal for tests

§Implementing a custom storage backend

Implement Storage to add your own persistence layer (SQLite, cloud sync, encrypted file, etc.):

use anyhow::Result;
use rustodo::models::Task;
use rustodo::storage::Storage;

struct MyStorage;

impl Storage for MyStorage {
    fn load(&self) -> Result<Vec<Task>> {
        // read from your backend
        Ok(vec![])
    }

    fn save(&self, tasks: &[Task]) -> Result<()> {
        // write to your backend
        Ok(())
    }

    fn location(&self) -> String {
        "my-backend".to_string()
    }
}

Re-exports§

pub use json::JsonStorage;
pub use memory::InMemoryStorage;
pub use json::get_data_file_path;

Modules§

json
JSON file-based storage implementation.
memory
In-memory storage implementation for testing

Traits§

Storage
Trait defining storage operations for tasks.