Created
March 11, 2024 16:26
-
-
Save MrCroxx/1965098d41e3aef0d39a4ac0d35aed9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro_rules! matches { | |
| ($expression:expr, $pattern:pat, $ok:expr, $err:expr) => { | |
| match $expression { | |
| $pattern => $ok, | |
| _ => panic!("unwrap_matches unmatched"), | |
| } | |
| }; | |
| } | |
| impl<K, V, ER, L, S> Entry<K, V, ER, L, S> | |
| where | |
| K: Key + Clone, | |
| V: Value, | |
| ER: std::error::Error + From<oneshot::error::RecvError>, | |
| L: CacheEventListener<K, V>, | |
| S: BuildHasher + Send + Sync + 'static, | |
| { | |
| pub fn into_fifo_entry(self) -> FifoEntry<K, V, ER, L, S> { | |
| matches! { self, Self::Fifo(entry), entry, panic!("into_fifo_entry() must be used on a fifo cache") } | |
| } | |
| pub fn into_lru_entry(self) -> LruEntry<K, V, ER, L, S> { | |
| matches! { self, Self::Lru(entry), entry, panic!("into_lru_entry() must be used on a lru cache") } | |
| } | |
| pub fn into_lfu_entry(self) -> LfuEntry<K, V, ER, L, S> { | |
| matches! { self, Self::Lfu(entry), entry, panic!("into_lfu_entry() must be used on a lfu cache") } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment