Crates.io | xorlist |
lib.rs | xorlist |
version | 0.1.1 |
source | src |
created_at | 2020-09-23 11:17:37.099436 |
updated_at | 2020-09-24 05:39:18.043416 |
description | xorlist |
homepage | https://github.com/bave/xorlist |
repository | https://github.com/bave/xorlist |
max_upload_size | |
id | 292044 |
size | 17,655 |
xorlist (rust library test)
[/tmp/test_xorlist]$ tree ./
./
├── Cargo.lock
├── Cargo.toml
└── src
└── main.rs
[package]
name = "test_xorlist"
version = "0.1.0"
authors = ["bave <inoue.tomoya@gmail.com>"]
edition = "2018"
[dependencies]
xorlist = { git = "https://github.com/bave/xorlist.git" }
extern crate xorlist;
use std::process::exit;
fn main() {
let mut xl = xorlist::XorList::new() as xorlist::XorList<u64>;
xl.push_back(1);
print!("xl.push_back(1)\n");
xl.push_back(2);
print!("xl.push_back(2)\n");
xl.push_front(0);
print!("xl.push_front(0)\n");
println!();
print!("xl.len() : {}\n", xl.len());
print!("pop_front() : {:?}\n", xl.pop_front());
print!("xl.len() : {}\n", xl.len());
print!("pop_back() : {:?}\n", xl.pop_back());
print!("xl.len() : {}\n", xl.len());
println!();
print!("for i in &xl {{ print!(\"{{}}\", i); }}\n");
for i in &xl {
print!("{} ", i);
}
println!();
print!("for i in &mut xl {{ *i = *i + 1; print!(\"{{}}\", i); }}\n");
for i in &mut xl {
*i = *i + 1;
print!("{} ", i);
}
println!();
//xl moved ownership
print!("for i in xl {{ print!(\"{{}}\", i + 1); }}\n");
for i in xl {
print!("{} ", i + 1);
}
println!();
println!();
let mut xl = xorlist::XorList::new() as xorlist::XorList<u64>;
for i in 0..5 {
xl.push_back(i);
}
let xl_iter_map_collect = xl.iter().map(|x| x + 1).collect::<Vec<u64>>();
print!("{:?}\n", xl_iter_map_collect);
let xl_iter_mut_map_collect = xl.iter_mut().map(|x| *x + 1).collect::<Vec<u64>>();
print!("{:?}\n", xl_iter_mut_map_collect);
//xl moved ownership
let xl_into_iter_map_collect = xl.into_iter().map(|x| x + 1).collect::<Vec<u64>>();
print!("{:?}\n", xl_into_iter_map_collect);
}
% cargo run
xl.push_back(1)
xl.push_back(2)
xl.push_front(0)
xl.len() : 3
pop_front() : Some(0)
xl.len() : 2
pop_back() : Some(2)
xl.len() : 1
for i in &xl { print!("{}", i); }
1
for i in &mut xl { *i = *i + 1; print!("{}", i); }
2
for i in xl { print!("{}", i + 1); }
3
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]