From 6f763ae6730a373a9fd7eb78110d91aa3bee9684 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 28 Jan 2020 11:34:25 +0100 Subject: [PATCH] tools: LruCache: add dropcheck marker See https://doc.rust-lang.org/nomicon/phantom-data.html Signed-off-by: Wolfgang Bumiller --- src/tools/lru_cache.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tools/lru_cache.rs b/src/tools/lru_cache.rs index 34b4c7ac..745c5ab8 100644 --- a/src/tools/lru_cache.rs +++ b/src/tools/lru_cache.rs @@ -5,6 +5,7 @@ //! is used to keep track of the cache access order. use std::collections::HashMap; +use std::marker::PhantomData; /// Interface for getting values on cache misses. pub trait Cacher { @@ -24,6 +25,8 @@ struct CacheNode { value: V, prev: *mut CacheNode, next: *mut CacheNode, + // Dropcheck marker. See the phantom-data section in the rustonomicon. + _marker: PhantomData>>, } impl CacheNode { @@ -33,6 +36,7 @@ impl CacheNode { value, prev: std::ptr::null_mut(), next: std::ptr::null_mut(), + _marker: PhantomData, } } } @@ -89,6 +93,8 @@ pub struct LruCache { head: *mut CacheNode, tail: *mut CacheNode, capacity: usize, + // Dropcheck marker. See the phantom-data section in the rustonomicon. + _marker: PhantomData>>, } impl LruCache { @@ -99,6 +105,7 @@ impl LruCache { head: std::ptr::null_mut(), tail: std::ptr::null_mut(), capacity, + _marker: PhantomData, } }