diff --git a/src/libcore/core.rc b/src/libcore/core.rc index f32895fb7ae..fa423809404 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -42,6 +42,9 @@ export extfmt; export tuple; export to_str; +// NDM seems to be necessary for resolve to work +export vec_iter, option_iter; + // FIXME: This creates some APIs that I do not want to commit to. It is // currently exported for the uv code in std, but when that code moves into // core this should become unexported @@ -144,16 +147,25 @@ mod f64; mod str; mod ptr; mod vec; +#[path="iter-trait"] +mod vec_iter { + #[path = "vec.rs"] + mod inst; +} mod bool; mod tuple; - // Ubiquitous-utility-type modules mod either; mod iter; mod logging; mod option; +#[path="iter-trait"] +mod option_iter { + #[path = "option.rs"] + mod inst; +} mod result; mod to_str; @@ -195,5 +207,4 @@ mod cmath; // indent-tabs-mode: nil // c-basic-offset: 4 // buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; // End: diff --git a/src/libcore/core.rs b/src/libcore/core.rs index d359cbf083d..8681f7d2a1c 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -7,7 +7,9 @@ import option = option::option; import path = path::path; import str::extensions; import vec::extensions; +import vec_iter::extensions; import option::extensions; +import option_iter::extensions; import ptr::extensions; export path, option, some, none, unreachable; diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs new file mode 100644 index 00000000000..8c23bb0ac54 --- /dev/null +++ b/src/libcore/iter-trait.rs @@ -0,0 +1,35 @@ +// This makes use of a clever hack that brson came up with to +// workaround our lack of traits and lack of macros. See core.{rc,rs} for +// how this file is used. + +import inst::{IMPL_T, EACH, SIZE_HINT}; +export extensions; + +impl extensions of iter::base_iter for IMPL_T { + fn each(blk: fn(A) -> bool) { EACH(self, blk) } + fn size_hint() -> option { SIZE_HINT(self) } + fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) } + fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } + fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } + fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { + iter::foldl(self, b0, blk) + } + fn contains(x: A) -> bool { iter::contains(self, x) } + fn count(x: A) -> uint { iter::count(self, x) } +} + +impl extensions for IMPL_T { + fn filter_to_vec(pred: fn(A) -> bool) -> [A] { + iter::filter_to_vec(self, pred) + } + fn map_to_vec(op: fn(A) -> B) -> [B] { iter::map_to_vec(self, op) } + fn to_vec() -> [A] { iter::to_vec(self) } + + // FIXME--bug in resolve prevents this from working + // fn flat_map_to_vec>(op: fn(A) -> IB) -> [B] { + // iter::flat_map_to_vec(self, op) + // } + + fn min() -> A { iter::min(self) } + fn max() -> A { iter::max(self) } +} diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs new file mode 100644 index 00000000000..530de27c614 --- /dev/null +++ b/src/libcore/iter-trait/option.rs @@ -0,0 +1,15 @@ +type IMPL_T = option; + +fn EACH(self: IMPL_T, f: fn(A) -> bool) { + alt self { + none { } + some(a) { f(a); } + } +} + +fn SIZE_HINT(self: IMPL_T) -> option { + alt self { + none { some(0u) } + some(_) { some(1u) } + } +} diff --git a/src/libcore/iter-trait/vec.rs b/src/libcore/iter-trait/vec.rs new file mode 100644 index 00000000000..62f9458303b --- /dev/null +++ b/src/libcore/iter-trait/vec.rs @@ -0,0 +1,9 @@ +type IMPL_T = [const A]; + +fn EACH(self: IMPL_T, f: fn(A) -> bool) { + vec::each(self, f) +} + +fn SIZE_HINT(self: IMPL_T) -> option { + some(vec::len(self)) +} diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 7b1bffaada1..80ccfc1422e 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1,115 +1,81 @@ -iface iterable { - fn iter(blk: fn(A)); +iface base_iter { + fn each(blk: fn(A) -> bool); + fn size_hint() -> option; } -impl of iterable for fn@(fn(A)) { - fn iter(blk: fn(A)) { - self(blk); - } -} - -// accomodate the fact that int/uint are passed by value by default: -impl of iterable for fn@(fn(int)) { - fn iter(blk: fn(&&int)) { - self {|i| blk(i)} - } -} - -impl of iterable for fn@(fn(uint)) { - fn iter(blk: fn(&&uint)) { - self {|i| blk(i)} - } -} - -impl of iterable for [A] { - fn iter(blk: fn(A)) { - vec::iter(self, blk) - } -} - -impl of iterable for option { - fn iter(blk: fn(A)) { - option::iter(self, blk) - } -} - -impl of iterable for str { - fn iter(blk: fn(&&char)) { - str::chars_iter(self) { |ch| blk(ch) } - } -} - -fn enumerate>(self: IA, blk: fn(uint, A)) { +fn eachi>(self: IA, blk: fn(uint, A) -> bool) { let mut i = 0u; - self.iter {|a| - blk(i, a); + for self.each {|a| + if !blk(i, a) { break; } i += 1u; } } -// Here: we have to use fn@ for predicates and map functions, because -// we will be binding them up into a closure. Disappointing. A true -// region type system might be able to do better than this. - -fn filter>(self: IA, prd: fn@(A) -> bool, blk: fn(A)) { - self.iter {|a| - if prd(a) { blk(a) } +fn all>(self: IA, blk: fn(A) -> bool) -> bool { + for self.each {|a| + if !blk(a) { ret false; } } + ret true; } -fn filter_map>(self: IA, cnv: fn@(A) -> option, - blk: fn(B)) { - self.iter {|a| - alt cnv(a) { - some(b) { blk(b) } - none { } +fn any>(self: IA, blk: fn(A) -> bool) -> bool { + for self.each {|a| + if blk(a) { ret true; } + } + ret false; +} + +fn filter_to_vec>(self: IA, + prd: fn(A) -> bool) -> [A] { + let mut result = []; + self.size_hint().iter {|hint| vec::reserve(result, hint); } + for self.each {|a| + if prd(a) { vec::push(result, a); } + } + ret result; +} + +fn map_to_vec>(self: IA, op: fn(A) -> B) -> [B] { + let mut result = []; + self.size_hint().iter {|hint| vec::reserve(result, hint); } + for self.each {|a| + vec::push(result, op(a)); + } + ret result; +} + +fn flat_map_to_vec,IB:base_iter>( + self: IA, op: fn(A) -> IB) -> [B] { + + let mut result = []; + for self.each {|a| + for op(a).each {|b| + vec::push(result, b); } } + ret result; } -fn map>(self: IA, cnv: fn@(A) -> B, blk: fn(B)) { - self.iter {|a| - let b = cnv(a); - blk(b); - } -} - -fn flat_map,IB:iterable>( - self: IA, cnv: fn@(A) -> IB, blk: fn(B)) { - self.iter {|a| - cnv(a).iter(blk) - } -} - -fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { +fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { let mut b <- b0; - self.iter {|a| - b <- blk(b, a); + for self.each {|a| + b = blk(b, a); } ret b; } -fn foldr>( - self: IA, +b0: B, blk: fn(A, B) -> B) -> B { - - let mut b <- b0; - reversed(self) {|a| - b <- blk(a, b); - } - ret b; -} - -fn to_vec>(self: IA) -> [A] { +fn to_vec>(self: IA) -> [A] { foldl::(self, [], {|r, a| r + [a]}) } -// FIXME: This could be made more efficient with an riterable interface -// #2005 -fn reversed>(self: IA, blk: fn(A)) { - vec::riter(to_vec(self), blk) +fn contains>(self: IA, x: A) -> bool { + for self.each {|a| + if a == x { ret true; } + } + ret false; } -fn count>(self: IA, x: A) -> uint { +fn count>(self: IA, x: A) -> uint { foldl(self, 0u) {|count, value| if value == x { count + 1u @@ -127,7 +93,7 @@ fn repeat(times: uint, blk: fn()) { } } -fn min>(self: IA) -> A { +fn min>(self: IA) -> A { alt foldl::,IA>(self, none) {|a, b| alt a { some(a_) if a_ < b { @@ -143,7 +109,7 @@ fn min>(self: IA) -> A { } } -fn max>(self: IA) -> A { +fn max>(self: IA) -> A { alt foldl::,IA>(self, none) {|a, b| alt a { some(a_) if a_ > b { @@ -159,6 +125,7 @@ fn max>(self: IA) -> A { } } +/* #[test] fn test_enumerate() { enumerate(["0", "1", "2"]) {|i,j| @@ -296,4 +263,5 @@ fn test_foldr() { } let sum = foldr([1, 2, 3, 4], 0, sub); assert sum == -2; -} \ No newline at end of file +} +*/ diff --git a/src/libcore/option.rs b/src/libcore/option.rs index db0d0030f83..3cf4bc92321 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -101,23 +101,6 @@ impl extensions for option { #[doc = "Performs an operation on the contained value or does nothing"] fn iter(f: fn(T)) { iter(self, f) } - #[doc = "Converts `none` to a zero-element list and `some` to a \ - one-element list."] - fn to_vec() -> [T] { - alt self { - some(t) { [t] } - none { [] } - } - } - - #[doc = "Performs an operation on the contained value or does nothing"] - fn each(f: fn(T) -> bool) { - alt self { - none { /* ok */ } - some(e) { f(e); } - } - } - #[doc = " Gets the value out of an option diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 191012e5156..ad1c3f2344a 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -494,7 +494,7 @@ holds. Apply function `f` to each element of `v` and return a vector containing only those elements for which `f` returned true. "] -fn filter(v: [T], f: fn(T) -> bool) -> [T] { +fn filter(v: [const T], f: fn(T) -> bool) -> [T] { let mut result = []; for each(v) {|elem| if f(elem) { result += [elem]; } @@ -970,23 +970,6 @@ fn unpack_slice(s: [const T]/&, f: fn(*T, uint) -> U) -> U unsafe { #[doc = "Extension methods for vectors"] impl extensions for [const T] { - #[doc = " - Return true if a vector contains an element with the given value - "] - #[inline] - fn contains(x: T) -> bool { contains(self, x) } - #[doc = "Returns the number of elements that are equal to a given value"] - #[inline] - fn count(x: T) -> uint { count(self, x) } - #[doc = "Iterates over a vector, with option to break"] - #[inline] - fn each(f: fn(T) -> bool) { each(self, f) } - #[doc = "Iterates over a vector's elements and indices"] - #[inline] - fn eachi(f: fn(uint, T) -> bool) { eachi(self, f) } - #[doc = "Reduce a vector from left to right"] - #[inline] - fn foldl(z: U, p: fn(U, T) -> U) -> U { foldl(z, self, p) } #[doc = "Reduce a vector from right to left"] #[inline] fn foldr(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) } @@ -1059,6 +1042,15 @@ impl extensions for [const T] { #[doc = "Extension methods for vectors"] impl extensions for [const T] { + #[doc = " + Construct a new vector from the elements of a vector for which some + predicate holds. + + Apply function `f` to each element of `v` and return a vector containing + only those elements for which `f` returned true. + "] + #[inline] + fn filter(f: fn(T) -> bool) -> [T] { filter(self, f) } #[doc = " Search for the first element that matches a given predicate @@ -1099,19 +1091,16 @@ impl extensions for [const T] { #[doc = "Extension methods for vectors"] impl extensions for [T] { #[doc = " - Return true if a predicate matches all elements - - If the vector contains no elements then true is returned. + Apply a function to each element of a vector and return the results "] #[inline] - fn all(f: fn(T) -> bool) -> bool { all(self, f) } + fn map(f: fn(T) -> U) -> [U] { map(self, f) } #[doc = " - Return true if a predicate matches any elements - - If the vector contains no elements then false is returned. + Apply a function to each element of a vector and return a concatenation + of each result vector "] #[inline] - fn any(f: fn(T) -> bool) -> bool { any(self, f) } + fn flat_map(f: fn(T) -> [U]) -> [U] { flat_map(self, f) } #[doc = " Apply a function to each element of a vector and return the results @@ -1122,32 +1111,8 @@ impl extensions for [T] { fn filter_map(f: fn(T) -> option) -> [U] { filter_map(self, f) } - #[doc = " - Apply a function eo each element of a vector and return a concatenation - of each result vector - "] - #[inline] - fn flat_map(f: fn(T) -> [U]) -> [U] { flat_map(self, f) } - #[doc = " - Apply a function to each element of a vector and return the results - "] - #[inline] - fn map(f: fn(T) -> U) -> [U] { map(self, f) } } -#[doc = "Extension methods for vectors"] -impl extensions for [T] { - #[doc = " - Construct a new vector from the elements of a vector for which some - predicate holds. - - Apply function `f` to each element of `v` and return a vector containing - only those elements for which `f` returned true. - "] - #[inline] - fn filter(f: fn(T) -> bool) -> [T] { filter(self, f) } - } - #[doc = "Unsafe operations"] mod unsafe { // FIXME: This should have crate visibility (#1893 blocks that) diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 42a17b8d481..bd0d8d916dd 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -7,14 +7,14 @@ fn start(+token: int) { import iter::*; let p = comm::port(); - let ch = iter::foldl(bind int::range(2, n_threads + 1, _), - comm::chan(p)) { |ch, i| + let mut ch = comm::chan(p); + int::range(2, n_threads + 1) { |i| let id = n_threads + 2 - i; let to_child = task::spawn_listener:: {|p| roundtrip(id, p, ch) }; - to_child - }; + ch = to_child; + } comm::send(ch, token); roundtrip(1, p, ch); } diff --git a/src/test/compile-fail/lub-in-args.rs b/src/test/compile-fail/lub-in-args.rs new file mode 100644 index 00000000000..8b59d12783b --- /dev/null +++ b/src/test/compile-fail/lub-in-args.rs @@ -0,0 +1,17 @@ +fn two_args(x: T, y: T) { } + +fn main() { + let x: [mut int] = [mut 3]; + let y: [int] = [3]; + let a: @mut int = @mut 3; + let b: @int = @3; + + // NOTE: + // + // The fact that this test fails to compile reflects a known + // shortcoming of the current inference algorithm. These errors + // are *not* desirable. + + two_args(x, y); //! ERROR (values differ in mutability) + two_args(a, b); //! ERROR (values differ in mutability) +} \ No newline at end of file diff --git a/src/test/run-pass/issue-2185.rs b/src/test/run-pass/issue-2185.rs index 4e5bb8d3041..eba99e3d86c 100644 --- a/src/test/run-pass/issue-2185.rs +++ b/src/test/run-pass/issue-2185.rs @@ -1,10 +1,40 @@ -import iter::*; +// This test had to do with an outdated version of the iterable iface. +// However, the condition it was testing seemed complex enough to +// warrant still having a test, so I inlined the old definitions. + +iface iterable { + fn iter(blk: fn(A)); +} + +impl of iterable for fn@(fn(A)) { + fn iter(blk: fn(A)) { self(blk); } +} + +impl of iterable for fn@(fn(uint)) { + fn iter(blk: fn(&&uint)) { self { |i| blk(i) } } +} + +fn filter>(self: IA, prd: fn@(A) -> bool, blk: fn(A)) { + self.iter {|a| + if prd(a) { blk(a) } + } +} + +fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { + let mut b <- b0; + self.iter { |a| + b <- blk(b, a); + } + ret b; +} fn main() { let range = bind uint::range(0u, 1000u, _); - let filt = bind iter::filter(range, {|&&n: uint| - n % 3u != 0u && n % 5u != 0u }, _); - let sum = iter::foldl(filt, 0u) {|accum, &&n: uint| accum + n }; + let filt = bind filter( + range, + {|&&n: uint| n % 3u != 0u && n % 5u != 0u }, + _); + let sum = foldl(filt, 0u) {|accum, &&n: uint| accum + n }; io::println(#fmt("%u", sum)); } \ No newline at end of file diff --git a/src/test/run-pass/iter-all.rs b/src/test/run-pass/iter-all.rs new file mode 100644 index 00000000000..1de45c97d19 --- /dev/null +++ b/src/test/run-pass/iter-all.rs @@ -0,0 +1,11 @@ +fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } + +fn main() { + assert ![1u, 2u].all(is_even); + assert [2u, 4u].all(is_even); + assert [].all(is_even); + + assert !some(1u).all(is_even); + assert some(2u).all(is_even); + assert none.all(is_even); +} \ No newline at end of file diff --git a/src/test/run-pass/iter-any.rs b/src/test/run-pass/iter-any.rs new file mode 100644 index 00000000000..40cd8a18039 --- /dev/null +++ b/src/test/run-pass/iter-any.rs @@ -0,0 +1,11 @@ +fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } + +fn main() { + assert ![1u, 3u].any(is_even); + assert [1u, 2u].any(is_even); + assert ![].any(is_even); + + assert !some(1u).any(is_even); + assert some(2u).any(is_even); + assert !none.any(is_even); +} \ No newline at end of file diff --git a/src/test/run-pass/iter-contains.rs b/src/test/run-pass/iter-contains.rs new file mode 100644 index 00000000000..5af80d47a10 --- /dev/null +++ b/src/test/run-pass/iter-contains.rs @@ -0,0 +1,10 @@ +fn main() { + assert [].contains(22u) == false; + assert [1u, 3u].contains(22u) == false; + assert [22u, 1u, 3u].contains(22u) == true; + assert [1u, 22u, 3u].contains(22u) == true; + assert [1u, 3u, 22u].contains(22u) == true; + assert none.contains(22u) == false; + assert some(1u).contains(22u) == false; + assert some(22u).contains(22u) == true; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-count.rs b/src/test/run-pass/iter-count.rs new file mode 100644 index 00000000000..54c9c1e2b73 --- /dev/null +++ b/src/test/run-pass/iter-count.rs @@ -0,0 +1,9 @@ +fn main() { + assert [].count(22u) == 0u; + assert [1u, 3u].count(22u) == 0u; + assert [22u, 1u, 3u].count(22u) == 1u; + assert [22u, 1u, 22u].count(22u) == 2u; + assert none.count(22u) == 0u; + assert some(1u).count(22u) == 0u; + assert some(22u).count(22u) == 1u; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-eachi.rs b/src/test/run-pass/iter-eachi.rs new file mode 100644 index 00000000000..30efd24a55f --- /dev/null +++ b/src/test/run-pass/iter-eachi.rs @@ -0,0 +1,18 @@ +fn main() { + let mut c = 0u; + for [1u, 2u, 3u, 4u, 5u].eachi { |i, v| + assert (i + 1u) == v; + c += 1u; + } + assert c == 5u; + + for none::.eachi { |i, v| fail; } + + let mut c = 0u; + for some(1u).eachi { |i, v| + assert (i + 1u) == v; + c += 1u; + } + assert c == 1u; + +} \ No newline at end of file diff --git a/src/test/run-pass/iter-filter-to-vec.rs b/src/test/run-pass/iter-filter-to-vec.rs new file mode 100644 index 00000000000..91b4eeffe7d --- /dev/null +++ b/src/test/run-pass/iter-filter-to-vec.rs @@ -0,0 +1,9 @@ +fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } + +fn main() { + assert [1u, 3u].filter_to_vec(is_even) == []; + assert [1u, 2u, 3u].filter_to_vec(is_even) == [2u]; + assert none.filter_to_vec(is_even) == []; + assert some(1u).filter_to_vec(is_even) == []; + assert some(2u).filter_to_vec(is_even) == [2u]; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-flat-map-to-vec.rs b/src/test/run-pass/iter-flat-map-to-vec.rs new file mode 100644 index 00000000000..d4395b487f4 --- /dev/null +++ b/src/test/run-pass/iter-flat-map-to-vec.rs @@ -0,0 +1,21 @@ +// xfail-test -- flat_map_to_vec currently disable + +fn repeat(&&x: uint) -> [uint] { [x, x] } + +fn incd_if_even(&&x: uint) -> option { + if (x % 2u) == 0u {some(x + 1u)} else {none} +} + +fn main() { + assert [1u, 3u].flat_map_to_vec(repeat) == [1u, 1u, 3u, 3u]; + assert [].flat_map_to_vec(repeat) == []; + assert none.flat_map_to_vec(repeat) == []; + assert some(1u).flat_map_to_vec(repeat) == [1u, 1u]; + assert some(2u).flat_map_to_vec(repeat) == [2u, 2u]; + + assert [1u, 2u, 5u].flat_map_to_vec(incd_if_even) == [3u]; + assert [].flat_map_to_vec(incd_if_even) == []; + assert none.flat_map_to_vec(incd_if_even) == []; + assert some(1u).flat_map_to_vec(incd_if_even) == []; + assert some(2u).flat_map_to_vec(incd_if_even) == [3u]; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-foldl.rs b/src/test/run-pass/iter-foldl.rs new file mode 100644 index 00000000000..9f5fafcd5bc --- /dev/null +++ b/src/test/run-pass/iter-foldl.rs @@ -0,0 +1,9 @@ +fn add(&&x: float, &&y: uint) -> float { x + (y as float) } + +fn main() { + assert [1u, 3u].foldl(20f, add) == 24f; + assert [].foldl(20f, add) == 20f; + assert none.foldl(20f, add) == 20f; + assert some(1u).foldl(20f, add) == 21f; + assert some(2u).foldl(20f, add) == 22f; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-map-to-vec.rs b/src/test/run-pass/iter-map-to-vec.rs new file mode 100644 index 00000000000..ea98196fbdd --- /dev/null +++ b/src/test/run-pass/iter-map-to-vec.rs @@ -0,0 +1,9 @@ +fn inc(&&x: uint) -> uint { x + 1u } + +fn main() { + assert [1u, 3u].map_to_vec(inc) == [2u, 4u]; + assert [1u, 2u, 3u].map_to_vec(inc) == [2u, 3u, 4u]; + assert none.map_to_vec(inc) == []; + assert some(1u).map_to_vec(inc) == [2u]; + assert some(2u).map_to_vec(inc) == [3u]; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-min-max.rs b/src/test/run-pass/iter-min-max.rs new file mode 100644 index 00000000000..338ba795111 --- /dev/null +++ b/src/test/run-pass/iter-min-max.rs @@ -0,0 +1,11 @@ +fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } + +fn main() { + assert [1u, 3u].min() == 1u; + assert [3u, 1u].min() == 1u; + assert some(1u).min() == 1u; + + assert [1u, 3u].max() == 3u; + assert [3u, 1u].max() == 3u; + assert some(3u).max() == 3u; +} \ No newline at end of file diff --git a/src/test/run-pass/iter-to-vec.rs b/src/test/run-pass/iter-to-vec.rs new file mode 100644 index 00000000000..1f7afdb1c7b --- /dev/null +++ b/src/test/run-pass/iter-to-vec.rs @@ -0,0 +1,7 @@ +fn main() { + assert [1u, 3u].to_vec() == [1u, 3u]; + assert [].to_vec() == []; + assert none.to_vec() == []; + assert some(1u).to_vec() == [1u]; + assert some(2u).to_vec() == [2u]; +} \ No newline at end of file