From 4618ccc2a2dbc73503c32464e2a05043e4f04227 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 27 Mar 2021 11:07:29 +0200 Subject: refactor: rename ChunkId::from_str to ChunkId::recreate Less confusion with FromStr::from_str this way. --- src/benchmark.rs | 2 +- src/chunkid.rs | 7 ++++--- src/client.rs | 2 +- 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 { - 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 { - 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 { let id: String = row.get(row.column_index("id")?)?; - Ok(ChunkId::from_str(&id)) + Ok(ChunkId::recreate(&id)) } } -- cgit v1.2.1