API Reference
Complete API documentation for Snapshot Comparison.
Structs
SnapshotStore
Manages snapshot storage and operations.
pub struct SnapshotStore {
base_dir: PathBuf,
}Methods
new
pub fn new(base_dir: PathBuf) -> SelfCreate a new snapshot store.
Arguments:
base_dir- Directory to store snapshots
Example:
let store = SnapshotStore::new(PathBuf::from("snapshots"));base_dir
pub fn base_dir(&self) -> &PathGet the base directory for this store.
create
pub fn create(
&self,
name: &str,
content: &[u8],
config: &SnapshotConfig
) -> Result<Snapshot, SnapshotError>Create a new snapshot.
Arguments:
name- Snapshot name (no path separators)content- Content to storeconfig- Configuration options
Returns:
Ok(Snapshot)- The created snapshotErr(SnapshotError)- On failure
read
pub fn read(&self, name: &str) -> Result<Snapshot, SnapshotError>Read a snapshot from disk.
check
pub fn check(
&self,
name: &str,
content: &[u8],
config: &SnapshotConfig
) -> Result<CompareResult, SnapshotError>Compare content against a stored snapshot.
Returns:
CompareResult::Match- Content matchesCompareResult::Mismatch { diff, .. }- Content differsCompareResult::Updated { .. }- Updated (ifupdate_mode)
update
pub fn update(
&self,
name: &str,
content: &[u8],
config: &SnapshotConfig
) -> Result<Snapshot, SnapshotError>Update an existing snapshot.
delete
pub fn delete(&self, name: &str) -> Result<(), SnapshotError>Delete a snapshot.
list
pub fn list(&self) -> Result<Vec<SnapshotMetadata>, SnapshotError>List all snapshots.
clean
pub fn clean(
&self,
keep: &[&str],
dry_run: bool
) -> Result<Vec<String>, SnapshotError>Remove snapshots not in the keep list.
Arguments:
keep- Names of snapshots to keepdry_run- If true, don't actually delete
Returns: Names of (would-be) deleted snapshots
SnapshotConfig
Configuration for snapshot operations.
pub struct SnapshotConfig {
pub file_type: Option<FileType>,
pub color: bool,
pub context_lines: usize,
pub update_mode: bool,
}Fields
| Field | Type | Default | Description |
|---|---|---|---|
file_type | Option<FileType> | None | File type hint (None = auto-detect) |
color | bool | false | Enable colored diff output |
context_lines | usize | 3 | Number of context lines in diffs |
update_mode | bool | false | Auto-update on mismatch |
Default
impl Default for SnapshotConfig {
fn default() -> Self {
Self {
file_type: None,
color: false,
context_lines: 3,
update_mode: false,
}
}
}Snapshot
A stored snapshot with metadata and content.
pub struct Snapshot {
pub metadata: SnapshotMetadata,
pub content: Vec<u8>,
}SnapshotMetadata
Metadata about a snapshot.
pub struct SnapshotMetadata {
pub name: String,
pub created_at: u64,
pub updated_at: u64,
pub content_hash: String,
pub size: usize,
pub file_type: FileType,
}Fields
| Field | Type | Description |
|---|---|---|
name | String | Snapshot name |
created_at | u64 | Unix timestamp of creation |
updated_at | u64 | Unix timestamp of last update |
content_hash | String | FNV-1a hash (hex string) |
size | usize | Content size in bytes |
file_type | FileType | Detected/specified file type |
Enums
CompareResult
Result of a snapshot comparison.
pub enum CompareResult {
Match,
Mismatch {
snapshot: Snapshot,
actual: Vec<u8>,
diff: DiffOutput,
},
Updated {
old_snapshot: Snapshot,
new_content: Vec<u8>,
},
}Variants
Match
Content matches the stored snapshot exactly.
Mismatch
Content differs from the snapshot.
| Field | Type | Description |
|---|---|---|
snapshot | Snapshot | The stored snapshot |
actual | Vec<u8> | The content being compared |
diff | DiffOutput | Detailed diff result |
Updated
Snapshot was updated (only in update_mode).
| Field | Type | Description |
|---|---|---|
old_snapshot | Snapshot | Previous snapshot |
new_content | Vec<u8> | New content stored |
Methods
impl CompareResult {
pub fn matches(&self) -> bool;
pub fn was_updated(&self) -> bool;
pub fn diff(&self) -> Option<&DiffOutput>;
}FileType
Supported file types.
pub enum FileType {
Text,
Json,
Binary,
}Re-exported from output_diffing_utility.
DiffOutput
Diff result from comparison.
pub enum DiffOutput {
Text(TextDiffResult),
Json(JsonDiffResult),
Binary(BinaryDiffResult),
}Methods
format
pub fn format(&self, snapshot_name: &str, color: bool) -> StringFormat the diff as a human-readable string.
has_changes
pub fn has_changes(&self) -> boolCheck if there are any changes.
SnapshotError
Error types for snapshot operations.
pub enum SnapshotError {
NotFound(String),
IoError(String),
InvalidName(String),
CorruptedSnapshot(String),
InvalidUtf8(String),
}Variants
| Variant | Description |
|---|---|
NotFound(name) | Snapshot does not exist |
IoError(msg) | File system error |
InvalidName(name) | Name contains forbidden characters |
CorruptedSnapshot(msg) | Snapshot file is corrupted |
InvalidUtf8(msg) | Content is not valid UTF-8 |
Traits
std::error::Errorstd::fmt::Displaystd::fmt::DebugClonePartialEqEq
Functions
hash_content
pub fn hash_content(content: &[u8]) -> u64Compute FNV-1a hash of content.
format_hash
pub fn format_hash(hash: u64) -> StringFormat hash as 16-character hex string.
Re-exports
From output_diffing_utility:
pub use output_diffing_utility::FileType;Constants
Validation
- Maximum snapshot name length: 255 characters
- Forbidden characters:
/,\,..,\0
File Format
- Extension:
.snap - Header delimiter:
--- - Header prefix:
#