#![doc = include_str!("../../docs/nodes.md")]
use std::path::PathBuf;
use std::{io, result};
pub use self::dense::{DenseLoader, DenseOpts, DenseReader, DenseStore};
pub use self::memory::{MemoryLoader, MemoryReader, MemoryStore};
pub use self::paged::{PagedLoader, PagedOpts, PagedReader, PagedStats, PagedStore};
pub use self::store::{
BulkLoad, FileStore, FixReport, LoadState, MAX_METADATA_BYTES, Metadata, Mode, NodeRead,
NodeReader, NodeStore, ReadOnly, ReadWrite,
};
use crate::Location;
mod codec;
mod dense;
mod file;
mod memory;
mod paged;
mod store;
pub mod prelude {
pub use super::store::{BulkLoad, FileStore, NodeRead, NodeReader, NodeStore};
}
pub const MAX_NODE_ID: u64 = (1 << 36) - 1;
#[derive(Debug, thiserror::Error)]
pub enum NodeStoreError {
#[error("{path}: {source}", path = .path.display())]
Io {
path: PathBuf,
source: io::Error,
},
#[error("{path} does not exist", path = .0.display())]
NotFound(PathBuf),
#[error("{path} is not a node store", path = .0.display())]
NotAStore(PathBuf),
#[error("{path} has format version {found}, but this library reads version {expected}", path = .path.display())]
UnsupportedVersion {
path: PathBuf,
found: u32,
expected: u32,
},
#[error("{path} is damaged: {reason}", path = .path.display())]
Corrupt {
path: PathBuf,
reason: String,
},
#[error("{path} needs fixing: {reason}", path = .path.display())]
NeedsFix {
path: PathBuf,
reason: String,
},
#[error("{path} has an interrupted commit; open it for writing once to roll it back", path = .0.display())]
NeedsRecovery(PathBuf),
#[error("{path} is open in another store, or in another process", path = .0.display())]
Locked(PathBuf),
#[error("node ID {0} is above the highest supported ID {max}", max = MAX_NODE_ID)]
IdTooLarge(u64),
#[error("node location {0:?} is outside ±90° latitude or ±180° longitude")]
InvalidLocation(Location),
#[error("node IDs must be loaded in ascending order: {id} after {last}")]
NotAscending {
id: u64,
last: u64,
},
#[error("node {0} differs from the one the interrupted load stored; is it the same input?")]
ResumeMismatch(u64),
#[error("bulk loading needs an empty store, or one whose bulk load was interrupted")]
NotEmpty,
#[error("the store's bulk load is not finished; resume it first")]
LoadUnfinished,
#[error("{path} failed part way through a commit; open it for writing again to roll the commit back", path = .0.display())]
Poisoned(PathBuf),
#[error(
"metadata keys take 1 to 255 bytes, and all metadata at most {MAX_METADATA_BYTES} bytes"
)]
MetadataTooLarge,
}
pub(crate) type Result<T, E = NodeStoreError> = result::Result<T, E>;