From 506ae934f808c2cf664f289dc29f7e90d253a454 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 27 Oct 2011 17:03:38 -0700 Subject: [PATCH] Reorder std::vec so the documentation renders better Put all types first, then predicates, then functions --- src/lib/vec.rs | 69 +++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 3763a13a37a..fd6e594e1ad 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -19,6 +19,41 @@ native "c-stack-cdecl" mod rustrt { count: uint) -> [T]; } +/* +Type: init_op + +A function used to initialize the elements of a vector. +*/ +type init_op = block(uint) -> T; + + +/* +Predicate: is_empty + +Returns true if a vector contains no elements. +*/ +pure fn is_empty(v: [mutable? T]) -> bool { + // FIXME: This would be easier if we could just call len + for t: T in v { ret false; } + ret true; +} + +/* +Predicate: is_not_empty + +Returns true if a vector contains some elements. +*/ +pure fn is_not_empty(v: [mutable? T]) -> bool { ret !is_empty(v); } + +/* +Predicate: same_length + +Returns true if two vectors have the same length +*/ +pure fn same_length(xs: [T], ys: [U]) -> bool { + vec::len(xs) == vec::len(ys) +} + /* Function: reserve @@ -43,13 +78,6 @@ Returns the length of a vector */ pure fn len(v: [mutable? T]) -> uint { unchecked { rusti::vec_len(v) } } -/* -Type: init_op - -A function used to initialize the elements of a vector. -*/ -type init_op = block(uint) -> T; - /* Function: init_fn @@ -141,24 +169,6 @@ fn from_mut(v: [mutable T]) -> [T] { ret vres; } -/* -Predicate: is_empty - -Returns true if a vector contains no elements. -*/ -pure fn is_empty(v: [mutable? T]) -> bool { - // FIXME: This would be easier if we could just call len - for t: T in v { ret false; } - ret true; -} - -/* -Predicate: is_not_empty - -Returns true if a vector contains some elements. -*/ -pure fn is_not_empty(v: [mutable? T]) -> bool { ret !is_empty(v); } - // Accessors /* @@ -519,15 +529,6 @@ fn position_pred(f: block(T) -> bool, v: [T]) -> option::t { ret none; } -/* -Predicate: same_length - -Returns true if two vectors have the same length -*/ -pure fn same_length(xs: [T], ys: [U]) -> bool { - vec::len(xs) == vec::len(ys) -} - // FIXME: if issue #586 gets implemented, could have a postcondition // saying the two result lists have the same length -- or, could // return a nominal record with a constraint saying that, instead of