|
|
@ -304,76 +304,76 @@ impl<'a, T> Drop for Drain<'a, T> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# fn main() {}
|
|
|
|
# fn main() {
|
|
|
|
|
|
|
|
# tests::create_push_pop();
|
|
|
|
#[cfg(test)]
|
|
|
|
# tests::iter_test();
|
|
|
|
mod tests {
|
|
|
|
# tests::test_drain();
|
|
|
|
use super::*;
|
|
|
|
# tests::test_zst();
|
|
|
|
#[test]
|
|
|
|
# }
|
|
|
|
fn create_push_pop() {
|
|
|
|
|
|
|
|
let mut v = Vec::new();
|
|
|
|
# mod tests {
|
|
|
|
v.push(1);
|
|
|
|
# use super::*;
|
|
|
|
assert_eq!(1, v.len());
|
|
|
|
# pub fn create_push_pop() {
|
|
|
|
assert_eq!(1, v[0]);
|
|
|
|
# let mut v = Vec::new();
|
|
|
|
for i in v.iter_mut() {
|
|
|
|
# v.push(1);
|
|
|
|
*i += 1;
|
|
|
|
# assert_eq!(1, v.len());
|
|
|
|
}
|
|
|
|
# assert_eq!(1, v[0]);
|
|
|
|
v.insert(0, 1);
|
|
|
|
# for i in v.iter_mut() {
|
|
|
|
let x = v.pop();
|
|
|
|
# *i += 1;
|
|
|
|
assert_eq!(Some(2), x);
|
|
|
|
# }
|
|
|
|
assert_eq!(1, v.len());
|
|
|
|
# v.insert(0, 1);
|
|
|
|
v.push(10);
|
|
|
|
# let x = v.pop();
|
|
|
|
let x = v.remove(0);
|
|
|
|
# assert_eq!(Some(2), x);
|
|
|
|
assert_eq!(1, x);
|
|
|
|
# assert_eq!(1, v.len());
|
|
|
|
assert_eq!(1, v.len());
|
|
|
|
# v.push(10);
|
|
|
|
}
|
|
|
|
# let x = v.remove(0);
|
|
|
|
|
|
|
|
# assert_eq!(1, x);
|
|
|
|
#[test]
|
|
|
|
# assert_eq!(1, v.len());
|
|
|
|
fn iter_test() {
|
|
|
|
# }
|
|
|
|
let mut v = Vec::new();
|
|
|
|
#
|
|
|
|
for i in 0..10 {
|
|
|
|
# pub fn iter_test() {
|
|
|
|
v.push(Box::new(i))
|
|
|
|
# let mut v = Vec::new();
|
|
|
|
}
|
|
|
|
# for i in 0..10 {
|
|
|
|
let mut iter = v.into_iter();
|
|
|
|
# v.push(Box::new(i))
|
|
|
|
let first = iter.next().unwrap();
|
|
|
|
# }
|
|
|
|
let last = iter.next_back().unwrap();
|
|
|
|
# let mut iter = v.into_iter();
|
|
|
|
drop(iter);
|
|
|
|
# let first = iter.next().unwrap();
|
|
|
|
assert_eq!(0, *first);
|
|
|
|
# let last = iter.next_back().unwrap();
|
|
|
|
assert_eq!(9, *last);
|
|
|
|
# drop(iter);
|
|
|
|
}
|
|
|
|
# assert_eq!(0, *first);
|
|
|
|
|
|
|
|
# assert_eq!(9, *last);
|
|
|
|
#[test]
|
|
|
|
# }
|
|
|
|
fn test_drain() {
|
|
|
|
#
|
|
|
|
let mut v = Vec::new();
|
|
|
|
# pub fn test_drain() {
|
|
|
|
for i in 0..10 {
|
|
|
|
# let mut v = Vec::new();
|
|
|
|
v.push(Box::new(i))
|
|
|
|
# for i in 0..10 {
|
|
|
|
}
|
|
|
|
# v.push(Box::new(i))
|
|
|
|
{
|
|
|
|
# }
|
|
|
|
let mut drain = v.drain();
|
|
|
|
# {
|
|
|
|
let first = drain.next().unwrap();
|
|
|
|
# let mut drain = v.drain();
|
|
|
|
let last = drain.next_back().unwrap();
|
|
|
|
# let first = drain.next().unwrap();
|
|
|
|
assert_eq!(0, *first);
|
|
|
|
# let last = drain.next_back().unwrap();
|
|
|
|
assert_eq!(9, *last);
|
|
|
|
# assert_eq!(0, *first);
|
|
|
|
}
|
|
|
|
# assert_eq!(9, *last);
|
|
|
|
assert_eq!(0, v.len());
|
|
|
|
# }
|
|
|
|
v.push(Box::new(1));
|
|
|
|
# assert_eq!(0, v.len());
|
|
|
|
assert_eq!(1, *v.pop().unwrap());
|
|
|
|
# v.push(Box::new(1));
|
|
|
|
}
|
|
|
|
# assert_eq!(1, *v.pop().unwrap());
|
|
|
|
|
|
|
|
# }
|
|
|
|
#[test]
|
|
|
|
#
|
|
|
|
fn test_zst() {
|
|
|
|
# pub fn test_zst() {
|
|
|
|
let mut v = Vec::new();
|
|
|
|
# let mut v = Vec::new();
|
|
|
|
for _i in 0..10 {
|
|
|
|
# for _i in 0..10 {
|
|
|
|
v.push(())
|
|
|
|
# v.push(())
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
|
|
|
|
#
|
|
|
|
let mut count = 0;
|
|
|
|
# let mut count = 0;
|
|
|
|
|
|
|
|
#
|
|
|
|
for _ in v.into_iter() {
|
|
|
|
# for _ in v.into_iter() {
|
|
|
|
count += 1
|
|
|
|
# count += 1
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
|
|
|
|
#
|
|
|
|
assert_eq!(10, count);
|
|
|
|
# assert_eq!(10, count);
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
```
|
|
|
|
```
|
|
|
|