use prelude::*;
use std::ops::{Index, IndexMut};
pub struct IgnoreWriteProp<T> {
read: T,
write: T,
}
impl<I, T: Clone> Index<I> for IgnoreWriteProp<T> {
type Output = T;
#[inline]
fn index(&self, _: I) -> &Self::Output {
&self.read
}
}
impl<I, T: Clone> IndexMut<I> for IgnoreWriteProp<T> {
#[inline]
fn index_mut(&mut self, _: I) -> &mut Self::Output {
self.write.clone_from(&self.read);
&mut self.write
}
}
impl<G, T> VertexPropMutNew<G, T> for IgnoreWriteProp<T>
where
G: WithVertex,
T: Clone,
{
fn new_vertex_prop(_: &G, value: T) -> Self {
IgnoreWriteProp {
read: value.clone(),
write: value,
}
}
}
impl<G, T> EdgePropMutNew<G, T> for IgnoreWriteProp<T>
where
G: WithEdge,
T: Clone,
{
fn new_edge_prop(_: &G, value: T) -> Self {
IgnoreWriteProp {
read: value.clone(),
write: value,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn basic() {
let n = 3;
let val = 7;
let g = CompleteGraph::new(n);
let mut p: IgnoreWriteProp<u32> = g.vertex_prop(val);
for i in 0..n {
assert_eq!(val, p[i]);
p[i] = 20;
for j in 0..n {
assert_eq!(val, p[j]);
}
}
}
}