diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-31 09:00:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-31 12:10:10 +0200 |
commit | acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f (patch) | |
tree | 1ce0288f878cac71990bb01f358d6035f1626c92 /src/genlist.rs | |
parent | 686e87981db210fa443404c8473dfe7a3f39b241 (diff) | |
download | obnam2-acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f.tar.gz |
docs: add documentation comments to crate
Also, make it an error for a public symbol to not be documented.
Sponsored-by: author
Diffstat (limited to 'src/genlist.rs')
-rw-r--r-- | src/genlist.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/genlist.rs b/src/genlist.rs index a81a997..3a0d81a 100644 --- a/src/genlist.rs +++ b/src/genlist.rs @@ -1,27 +1,39 @@ +//! A list of generations on the server. + use crate::chunkid::ChunkId; use crate::generation::{FinishedGeneration, GenId}; +/// A list of generations on the server. pub struct GenerationList { list: Vec<FinishedGeneration>, } +/// Possible errors from listing generations. #[derive(Debug, thiserror::Error)] pub enum GenerationListError { + /// Server doesn't know about a generation. #[error("Unknown generation: {0}")] UnknownGeneration(ChunkId), } impl GenerationList { + /// Create a new list of generations. pub fn new(gens: Vec<FinishedGeneration>) -> Self { let mut list = gens; list.sort_by_cached_key(|gen| gen.ended().to_string()); Self { list } } + /// Return an iterator over the generations. pub fn iter(&self) -> impl Iterator<Item = &FinishedGeneration> { self.list.iter() } + /// Resolve a symbolic name of a generation into its identifier. + /// + /// For example, "latest" refers to the latest backup, but needs + /// to be resolved into an actual, immutable id to actually be + /// restored. pub fn resolve(&self, genref: &str) -> Result<GenId, GenerationListError> { let gen = if self.list.is_empty() { None |