Skip to content

Commit

Permalink
Constant access type
Browse files Browse the repository at this point in the history
Mostly for testing purposes
  • Loading branch information
vorner committed Aug 9, 2019
1 parent d2119fc commit e472d8b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ where
}
}

/// TODO
pub struct ConstantDeref<T>(T);

impl<T> Deref for ConstantDeref<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}

/// TODO
pub struct Constant<T>(pub T);

impl<T: Clone> Access<T> for Constant<T> {
type Guard = ConstantDeref<T>;
fn load(&self) -> Self::Guard {
ConstantDeref(self.0.clone())
}
}

#[cfg(test)]
mod tests {
use super::super::{ArcSwap, ArcSwapOption};
Expand Down Expand Up @@ -246,4 +266,12 @@ mod tests {
check_static_dispatch_direct(&map);
check_dyn_dispatch_direct(&map);
}

#[test]
fn constant() {
let c = Constant(42);
check_static_dispatch_direct(&c);
check_dyn_dispatch_direct(&c);
check_static_dispatch_direct(c);
}
}

0 comments on commit e472d8b

Please sign in to comment.