33//! # example
44//! see [`IteratorDirection`]
55
6+ #![ allow( deprecated) ]
67use std:: iter:: FusedIterator ;
78
89use rayon:: iter:: {
@@ -12,9 +13,53 @@ use rayon::iter::{
1213#[ cfg( feature = "serde-serialize" ) ]
1314use serde:: { Deserialize , Serialize } ;
1415
15- use super :: { super :: Direction , IteratorElement , RandomAccessIterator } ;
16+ use super :: { super :: Direction , DoubleEndedCounter , IteratorElement } ;
17+ use crate :: lattice:: OrientedDirection ;
1618
17- /// Iterator over [`Direction`] with the same sign.
19+ /// Iterator over [`OrientedDirection`].
20+ /// # Example
21+ /// ```
22+ /// # use lattice_qcd_rs::lattice::{IteratorOrientedDirection, OrientedDirection, IteratorElement};
23+ /// # use lattice_qcd_rs::error::ImplementationError;
24+ /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
25+ /// let mut iter = IteratorOrientedDirection::<4, true>::new();
26+ ///
27+ /// let iter_val = iter.next();
28+ /// // debug
29+ /// println!("{iter_val:?}, {:?}", OrientedDirection::<4, true>::new(0));
30+ ///
31+ /// assert_eq!(
32+ /// iter_val.ok_or(ImplementationError::OptionWithUnexpectedNone)?,
33+ /// OrientedDirection::<4, true>::new(0)
34+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?
35+ /// );
36+ /// assert_eq!(
37+ /// iter.next()
38+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?,
39+ /// OrientedDirection::<4, true>::new(1)
40+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?
41+ /// );
42+ /// assert_eq!(
43+ /// iter.next()
44+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?,
45+ /// OrientedDirection::<4, true>::new(2)
46+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?
47+ /// );
48+ /// assert_eq!(
49+ /// iter.next()
50+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?,
51+ /// OrientedDirection::<4, true>::new(3)
52+ /// .ok_or(ImplementationError::OptionWithUnexpectedNone)?
53+ /// );
54+ /// assert_eq!(iter.next(), None);
55+ /// assert_eq!(iter.next(), None);
56+ /// # Ok(())
57+ /// # }
58+ /// ```
59+ pub type IteratorOrientedDirection < const D : usize , const ORIENTATION : bool > =
60+ DoubleEndedCounter < OrientedDirection < D , ORIENTATION > > ;
61+
62+ /// Iterator over [`Direction`] with the orientation.
1863/// # Example
1964/// ```
2065/// # use lattice_qcd_rs::lattice::{IteratorDirection, Direction, IteratorElement};
@@ -47,9 +92,13 @@ use super::{super::Direction, IteratorElement, RandomAccessIterator};
4792/// # Ok(())
4893/// # }
4994/// ```
50- // TODO
95+ // TODO remove ?
5196#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Hash ) ]
5297#[ cfg_attr( feature = "serde-serialize" , derive( Serialize , Deserialize ) ) ]
98+ #[ deprecated(
99+ since = "0.3.0" ,
100+ note = "use `IteratorOrientedDirection` instead with a map and a conversion"
101+ ) ]
53102pub struct IteratorDirection < const D : usize , const IS_POSITIVE_DIRECTION : bool > {
54103 /// Front element of the iterator. The state need to be increased before
55104 /// being returned by the next [`Iterator::next`] call.
0 commit comments