local-store
ローカルストレージ管理を完全に閉じる装置 — path 解決 + ACID file/dir storage + atomic IO + format dispatch。
version-migrate の基盤として使われているほか、スキーマバージョン管理が不要なアプリケーションでも standalone で利用できます。
API Philosophy
fallback 所有: PathStrategy::default() は System (OS 標準ディレクトリ) に解決します。caller 側に fallback ロジックを漏らしません。
category 受け: DirStorage の category 引数は impl Into<String> で受けます。enum で固定せず、typo 防止の責務は caller 側に委ねます。
PathBuf 露出は現状維持: AppPaths::config_dir() 等は PathBuf を返します。高レベルな読み書きは FileStorage / DirStorage が担うため、raw path の完全な非露出化は将来の検討事項です。
Features
- Platform-Agnostic Paths:
AppPaths+PathStrategyで Linux / macOS / Windows のパス解決を統一 - Atomic File IO: write-to-temp + rename による ACID 保証 (
atomic_ioモジュール) - FileStorage: 単一ファイル設定向けの ACID ストレージ (TOML / JSON、retry、format 変換)
- DirStorage: エンティティをファイル単位で管理するディレクトリストレージ (
FilenameEncoding付き) - AsyncDirStorage:
asyncfeature フラグで有効になる非同期版 DirStorage (tokio::fs使用) - Format Dispatch:
FormatStrategyで TOML / JSON を切り替え、format_convertで相互変換 - Minimal Dependencies:
dirs+thiserrorのみが必須依存
Quick Start
[]
= "0.1.0"
= { = "1.0", = ["derive"] }
= "1.0"
use ;
use ;
Main API
| 型 / モジュール | 役割 |
|---|---|
AppPaths |
アプリ名からコンフィグ・データディレクトリを解決 |
PathStrategy |
System / Xdg / CustomBase の解決戦略 |
PrefPath |
個別ファイルパスの抽象 |
FileStorage |
単一ファイル ACID ストレージ |
FileStorageStrategy |
FileStorage の設定 (format / retry / load behavior) |
FormatStrategy |
Json / Toml の切り替え |
LoadBehavior |
CreateIfMissing / SaveIfMissing / ErrorIfMissing |
DirStorage |
ディレクトリ単位のエンティティ管理 (sync) |
AsyncDirStorage |
非同期版 DirStorage (async feature 必須) |
DirStorageStrategy |
DirStorage の設定 |
FilenameEncoding |
Plain / UrlEncode / Base64 |
StoreError |
ストレージ操作の統合エラー型 |
IoOperationKind |
エラー診断用の操作種別 |
atomic_io |
write-to-temp + atomic rename の低レベル操作 |
format_convert |
JSON ↔ TOML 変換ユーティリティ |
Crate Relationship
local-store ← 基盤: path 解決 + ACID IO + format dispatch
↑
version-migrate ← schema 進化を上に乗せる (FileStorage / DirStorage を再エクスポート)
version-migrate の FileStorage / DirStorage は local-store の薄いラッパーです。raw IO と format 変換のロジックはすべて local-store に集約されています。スキーマバージョン管理が不要な場合は local-store を直接使用できます。
Async Support
[]
= { = "0.1.0", = ["async"] }
= { = "1.0", = ["full"] }
use ;
async
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.