@@ -102,7 +102,7 @@ impl ImageRegistry {
102102 }
103103
104104 drop ( conn) ;
105- snapshot. map ( SnapshotId )
105+ snapshot. map ( SnapshotId :: new )
106106 }
107107
108108 /// Insert or update a cache entry.
@@ -118,10 +118,11 @@ impl ImageRegistry {
118118 } ;
119119
120120 // INSERT OR REPLACE handles both new and updated entries.
121+ let snapshot_id: & str = snapshot. as_ref ( ) ;
121122 let _result = conn. execute (
122123 "INSERT OR REPLACE INTO snapshots (key, snapshot_id, accessed_at)
123124 VALUES (?1, ?2, ?3)" ,
124- rusqlite:: params![ key, snapshot . 0 , now] ,
125+ rusqlite:: params![ key, snapshot_id , now] ,
125126 ) ;
126127
127128 drop ( conn) ;
@@ -149,7 +150,7 @@ impl ImageRegistry {
149150 }
150151
151152 drop ( conn) ;
152- snapshot. map ( SnapshotId )
153+ snapshot. map ( SnapshotId :: new )
153154 }
154155
155156 /// Returns the number of cached entries.
@@ -193,7 +194,9 @@ impl ImageRegistry {
193194 } ;
194195
195196 let evicted: Vec < SnapshotId > = stmt
196- . query_map ( [ overflow] , |row| row. get :: < _ , String > ( 0 ) . map ( SnapshotId ) )
197+ . query_map ( [ overflow] , |row| {
198+ row. get :: < _ , String > ( 0 ) . map ( SnapshotId :: new)
199+ } )
197200 . ok ( )
198201 . map ( |rows| rows. filter_map ( Result :: ok) . collect ( ) )
199202 . unwrap_or_default ( ) ;
@@ -234,25 +237,25 @@ mod tests {
234237 #[ test]
235238 fn put_then_get_returns_snapshot ( ) {
236239 let ( reg, _dir) = open_temp ( 10 ) ;
237- let snap = SnapshotId ( "snap-abc" . into ( ) ) ;
240+ let snap = SnapshotId :: new ( "snap-abc" ) ;
238241 let evicted = reg. put ( "my-key" , & snap) ;
239242 assert ! ( evicted. is_empty( ) ) ;
240243
241244 let got = reg. get ( "my-key" ) ;
242- assert_eq ! ( got, Some ( SnapshotId ( "snap-abc" . into ( ) ) ) ) ;
245+ assert_eq ! ( got, Some ( SnapshotId :: new ( "snap-abc" ) ) ) ;
243246 }
244247
245248 #[ test]
246249 fn get_updates_access_time ( ) {
247250 let ( reg, _dir) = open_temp ( 2 ) ;
248251
249252 // Insert a, then b. "a" is older by insertion order.
250- reg. put ( "a" , & SnapshotId ( "snap-a" . into ( ) ) ) ;
253+ reg. put ( "a" , & SnapshotId :: new ( "snap-a" ) ) ;
251254
252255 // Tiny sleep so timestamps differ.
253256 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
254257
255- reg. put ( "b" , & SnapshotId ( "snap-b" . into ( ) ) ) ;
258+ reg. put ( "b" , & SnapshotId :: new ( "snap-b" ) ) ;
256259
257260 // Touch "a" so it becomes the most recently accessed.
258261 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
@@ -261,10 +264,10 @@ mod tests {
261264 // Now insert "c" -- capacity is 2, so one must be evicted.
262265 // "b" should be evicted since "a" was touched more recently.
263266 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
264- let evicted = reg. put ( "c" , & SnapshotId ( "snap-c" . into ( ) ) ) ;
267+ let evicted = reg. put ( "c" , & SnapshotId :: new ( "snap-c" ) ) ;
265268
266269 assert_eq ! ( evicted. len( ) , 1 ) ;
267- assert_eq ! ( evicted[ 0 ] , SnapshotId ( "snap-b" . into ( ) ) ) ;
270+ assert_eq ! ( evicted[ 0 ] , SnapshotId :: new ( "snap-b" ) ) ;
268271
269272 // "a" should still be present.
270273 assert ! ( reg. get( "a" ) . is_some( ) ) ;
@@ -276,16 +279,16 @@ mod tests {
276279 fn eviction_returns_overflow_entries ( ) {
277280 let ( reg, _dir) = open_temp ( 2 ) ;
278281
279- reg. put ( "x" , & SnapshotId ( "snap-x" . into ( ) ) ) ;
282+ reg. put ( "x" , & SnapshotId :: new ( "snap-x" ) ) ;
280283 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
281- reg. put ( "y" , & SnapshotId ( "snap-y" . into ( ) ) ) ;
284+ reg. put ( "y" , & SnapshotId :: new ( "snap-y" ) ) ;
282285 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
283286
284287 // This third insert should evict the oldest ("x").
285- let evicted = reg. put ( "z" , & SnapshotId ( "snap-z" . into ( ) ) ) ;
288+ let evicted = reg. put ( "z" , & SnapshotId :: new ( "snap-z" ) ) ;
286289
287290 assert_eq ! ( evicted. len( ) , 1 ) ;
288- assert_eq ! ( evicted[ 0 ] , SnapshotId ( "snap-x" . into ( ) ) ) ;
291+ assert_eq ! ( evicted[ 0 ] , SnapshotId :: new ( "snap-x" ) ) ;
289292 assert_eq ! ( reg. len( ) , 2 ) ;
290293 }
291294
@@ -296,25 +299,25 @@ mod tests {
296299
297300 {
298301 let reg = ImageRegistry :: open ( & db_path, 10 ) . expect ( "open" ) ;
299- reg. put ( "persistent" , & SnapshotId ( "snap-persist" . into ( ) ) ) ;
302+ reg. put ( "persistent" , & SnapshotId :: new ( "snap-persist" ) ) ;
300303 assert_eq ! ( reg. len( ) , 1 ) ;
301304 // reg is dropped here, closing the connection.
302305 }
303306
304307 let reg2 = ImageRegistry :: open ( & db_path, 10 ) . expect ( "reopen" ) ;
305308 assert_eq ! ( reg2. len( ) , 1 ) ;
306309 let got = reg2. get ( "persistent" ) ;
307- assert_eq ! ( got, Some ( SnapshotId ( "snap-persist" . into ( ) ) ) ) ;
310+ assert_eq ! ( got, Some ( SnapshotId :: new ( "snap-persist" ) ) ) ;
308311 }
309312
310313 #[ test]
311314 fn invalidate_returns_removed_snapshot ( ) {
312315 let ( reg, _dir) = open_temp ( 10 ) ;
313- let snap = SnapshotId ( "snap-rm" . into ( ) ) ;
316+ let snap = SnapshotId :: new ( "snap-rm" ) ;
314317 reg. put ( "to-remove" , & snap) ;
315318
316319 let removed = reg. invalidate ( "to-remove" ) ;
317- assert_eq ! ( removed, Some ( SnapshotId ( "snap-rm" . into ( ) ) ) ) ;
320+ assert_eq ! ( removed, Some ( SnapshotId :: new ( "snap-rm" ) ) ) ;
318321 assert ! ( reg. get( "to-remove" ) . is_none( ) ) ;
319322 assert_eq ! ( reg. len( ) , 0 ) ;
320323
0 commit comments