• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::sync::atomic::AtomicUsize;
2 use std::sync::atomic::Ordering;
3 
4 /// Cached size field used in generated code.
5 /// It is always equal to itself to simplify generated code.
6 /// (Generated code can use `#[derive(Eq)]`).
7 #[derive(Debug, Default)]
8 pub struct CachedSize {
9     size: AtomicUsize,
10 }
11 
12 impl CachedSize {
13     /// Get cached size
get(&self) -> u3214     pub fn get(&self) -> u32 {
15         self.size.load(Ordering::Relaxed) as u32
16     }
17 
18     /// Set cached size
set(&self, size: u32)19     pub fn set(&self, size: u32) {
20         self.size.store(size as usize, Ordering::Relaxed)
21     }
22 }
23 
24 impl Clone for CachedSize {
clone(&self) -> CachedSize25     fn clone(&self) -> CachedSize {
26         CachedSize {
27             size: AtomicUsize::new(self.size.load(Ordering::Relaxed)),
28         }
29     }
30 }
31 
32 impl PartialEq<CachedSize> for CachedSize {
eq(&self, _other: &CachedSize) -> bool33     fn eq(&self, _other: &CachedSize) -> bool {
34         true
35     }
36 }
37 
38 impl Eq for CachedSize {}
39