1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Serde-based disk persistence for petgraph graphs.
//!
//! Enabled with the `snapshot` feature flag. Optional compression:
//! - `snapshot-zstd` — Zstd compression
//! - `snapshot-lz4` — LZ4 compression via `lz4_flex` (pure Rust)
//!
//! Snapshots are stored as `{name}-{sanitized_key}.{ext}` files. The key is
//! encoded in the filename so two saves with the same key overwrite each other.
//! Rotation keeps the latest `keep` files by filesystem mtime.
//!
//! [`inspect`] and [`list`] use partial reads for uncompressed bincode files —
//! only the `8 + meta_len` byte header is read from disk; graph bytes are never loaded.
//!
//! # Quick start
//!
//! ```rust
//! # use std::path::PathBuf;
//! use petgraph::Graph;
//! use petgraph_live::snapshot::{
//! Compression, SnapshotConfig, SnapshotFormat, load_or_build, inspect, list,
//! };
//!
//! # let dir = tempfile::tempdir().unwrap();
//! let cfg = SnapshotConfig {
//! dir: dir.path().to_path_buf(),
//! name: "graph".into(),
//! key: Some("v1".into()),
//! format: SnapshotFormat::Bincode,
//! compression: Compression::None,
//! keep: 3,
//! };
//!
//! // Load from disk or build from scratch on first run.
//! let graph: Graph<String, String> = load_or_build(&cfg, || {
//! let mut g: Graph<String, String> = Graph::new();
//! let a = g.add_node("A".into());
//! let b = g.add_node("B".into());
//! g.add_edge(a, b, "edge".into());
//! Ok(g)
//! })?;
//!
//! // Inspect metadata without loading the graph.
//! if let Some(meta) = inspect(&cfg)? {
//! println!("{} nodes, key={}", meta.node_count, meta.key);
//! }
//!
//! // List all retained snapshots, oldest first.
//! for (path, meta) in list(&cfg)? {
//! println!("{}: {} nodes", path.display(), meta.node_count);
//! }
//! # Ok::<_, petgraph_live::snapshot::SnapshotError>(())
//! ```
pub use ;
pub use SnapshotError;
pub use ;
pub use SnapshotMeta;