diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-27 11:07:29 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-27 11:07:29 +0200 |
commit | 4618ccc2a2dbc73503c32464e2a05043e4f04227 (patch) | |
tree | 8bfecd8bbffa235d98ca852b8970027a28175182 | |
parent | 5af0888b60ba124d537efda829a5ba3f7130d07a (diff) | |
download | obnam2-4618ccc2a2dbc73503c32464e2a05043e4f04227.tar.gz |
refactor: rename ChunkId::from_str to ChunkId::recreate
Less confusion with FromStr::from_str this way.
-rw-r--r-- | src/benchmark.rs | 2 | ||||
-rw-r--r-- | src/chunkid.rs | 7 | ||||
-rw-r--r-- | src/client.rs | 2 | ||||
-rw-r--r-- | src/index.rs | 2 |
4 files changed, 7 insertions, 6 deletions
diff --git a/src/benchmark.rs b/src/benchmark.rs index b484aa1..d214939 100644 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -21,7 +21,7 @@ impl Iterator for ChunkGenerator { if self.next >= self.goal { None } else { - let id = ChunkId::from_str(&format!("{}", self.next)); + let id = ChunkId::recreate(&format!("{}", self.next)); let checksum = id.sha256(); let meta = ChunkMeta::new(&checksum); let chunk = DataChunk::new(vec![]); diff --git a/src/chunkid.rs b/src/chunkid.rs index 3933d4b..2f67d79 100644 --- a/src/chunkid.rs +++ b/src/chunkid.rs @@ -37,7 +37,8 @@ impl ChunkId { } } - pub fn from_str(s: &str) -> Self { + /// Re-construct an identifier from a previous values. + pub fn recreate(s: &str) -> Self { ChunkId { id: s.to_string() } } @@ -85,7 +86,7 @@ impl FromStr for ChunkId { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { - Ok(ChunkId::from_str(s)) + Ok(ChunkId::recreate(s)) } } @@ -117,6 +118,6 @@ mod test { fn survives_round_trip() { let id = ChunkId::new(); let id_str = id.to_string(); - assert_eq!(id, ChunkId::from_str(&id_str)) + assert_eq!(id, ChunkId::recreate(&id_str)) } } diff --git a/src/client.rs b/src/client.rs index f74e184..c054aca 100644 --- a/src/client.rs +++ b/src/client.rs @@ -341,7 +341,7 @@ impl BackupClient { } fn fetch_generation_chunk(&self, gen_id: &str) -> ClientResult<GenerationChunk> { - let chunk_id = ChunkId::from_str(gen_id); + let chunk_id = ChunkId::recreate(gen_id); let chunk = self.fetch_chunk(&chunk_id)?; let gen = GenerationChunk::from_data_chunk(&chunk)?; Ok(gen) diff --git a/src/index.rs b/src/index.rs index 9386e73..c8d8d86 100644 --- a/src/index.rs +++ b/src/index.rs @@ -272,6 +272,6 @@ mod sql { fn row_to_id(row: &Row) -> rusqlite::Result<ChunkId> { let id: String = row.get(row.column_index("id")?)?; - Ok(ChunkId::from_str(&id)) + Ok(ChunkId::recreate(&id)) } } |