collection_tools 0.49.0

General purpose tools to manipulate collections( containers like Vec/HashMap/HashSet ).
Documentation
use super :: *;

#[ test ]
fn reexport() 
{
  let mut map: the_module ::VecDeque< i32 > = the_module ::VecDeque ::new();
  map.push_back(1);
  assert!(map.contains(&1));
  assert!(!map.contains(&2));
}

#[ cfg( feature = "collection_constructors" ) ]
#[ test ]
fn constructor() 
{
  // test.case( "empty" );
  let got: the_module ::VecDeque< i32 > = the_module ::deque! {};
  let exp = the_module ::VecDeque ::new();
  assert_eq!(got, exp);

  // test.case( "multiple entry" );
  let got = the_module ::deque! { 3, 13 };
  let mut exp = the_module ::VecDeque ::new();
  exp.push_front(13);
  exp.push_front(3);
  assert_eq!(got, exp);

  let _got = the_module ::deque!("b");
  let _got = the_module ::exposed ::deque!("b");
}

#[ cfg( feature = "collection_into_constructors" ) ]
#[ test ]
fn into_constructor() 
{
  // test.case( "empty" );
  let got: the_module ::VecDeque< i32 > = the_module ::into_vecd! {};
  let exp = the_module ::VecDeque ::new();
  assert_eq!(got, exp);

  // test.case( "single entry" );
  let got = the_module ::into_vecd! { 3, 13 };
  let mut exp = the_module ::VecDeque ::new();
  exp.push_front(13);
  exp.push_front(3);
  assert_eq!(got, exp);

  let _got = the_module ::deque!("b");
  let _got = the_module ::exposed ::deque!("b");
}

#[ test ]
fn iters() 
{
  struct MyContainer 
  {
  entries: the_module ::VecDeque< i32 >,
 }

  impl IntoIterator for MyContainer 
  {
  type Item = i32;
  type IntoIter = the_module ::vec_deque ::IntoIter< i32 >;

  fn into_iter(self) -> Self ::IntoIter 
  {
   self.entries.into_iter()
 }
 }

  impl< 'a > IntoIterator for &'a MyContainer 
{
  type Item = &'a i32;
  type IntoIter = the_module ::vec_deque ::Iter< 'a, i32 >;

  fn into_iter(self) -> Self ::IntoIter 
  {
   self.entries.iter()
 }
 }

  impl< 'a > IntoIterator for &'a mut MyContainer 
{
  type Item = &'a mut i32;
  type IntoIter = the_module ::vec_deque ::IterMut< 'a, i32 >;

  fn into_iter(self) -> Self ::IntoIter 
  {
   self.entries.iter_mut()
 }
 }

  let instance = MyContainer {
  entries: the_module ::VecDeque ::from([1, 2, 3]),
 };
  let got: the_module ::VecDeque< _ > = instance.into_iter().collect();
  let exp = the_module ::VecDeque ::from([1, 2, 3]);
  assert_eq!(got, exp);

  let instance = MyContainer {
  entries: the_module ::VecDeque ::from([1, 2, 3]),
 };
  let got: the_module ::VecDeque< _ > = (&instance).into_iter().copied().collect();
  let exp = the_module ::VecDeque ::from([1, 2, 3]);
  assert_eq!(got, exp);

  let mut instance = MyContainer {
  entries: the_module ::VecDeque ::from([1, 2, 3]),
 };
  (&mut instance).into_iter().for_each(|v| *v *= 2);
  let exp = the_module ::VecDeque ::from([2, 4, 6]);
  assert_eq!(instance.entries, exp);
}