Convert all kind bounds to camel case. Remove send, owned keywords.
This commit is contained in:
@@ -89,7 +89,7 @@ pure fn build_sized_opt<A>(size: Option<uint>,
|
||||
|
||||
// Appending
|
||||
#[inline(always)]
|
||||
pure fn append<T: copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
||||
pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
|
||||
do build_sized(lhs.len() + rhs.len()) |push| {
|
||||
for vec::each(lhs) |x| { push(x); }
|
||||
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
|
||||
@@ -125,7 +125,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
pure fn from_elem<T: copy>(n_elts: uint, t: T) -> @[T] {
|
||||
pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
|
||||
do build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts { push(t); i += 1u; }
|
||||
@@ -133,7 +133,7 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> @[T] {
|
||||
}
|
||||
|
||||
#[cfg(notest)]
|
||||
impl<T: copy> @[T]: Add<&[const T],@[T]> {
|
||||
impl<T: Copy> @[T]: Add<&[const T],@[T]> {
|
||||
#[inline(always)]
|
||||
pure fn add(rhs: &[const T]) -> @[T] {
|
||||
append(self, rhs)
|
||||
|
||||
@@ -48,7 +48,7 @@ export listen;
|
||||
* transmitted. If a port value is copied, both copies refer to the same
|
||||
* port. Ports may be associated with multiple `chan`s.
|
||||
*/
|
||||
enum Port<T: send> {
|
||||
enum Port<T: Send> {
|
||||
Port_(@PortPtr<T>)
|
||||
}
|
||||
|
||||
@@ -64,16 +64,16 @@ enum Port<T: send> {
|
||||
* data will be silently dropped. Channels may be duplicated and
|
||||
* themselves transmitted over other channels.
|
||||
*/
|
||||
enum Chan<T: send> {
|
||||
enum Chan<T: Send> {
|
||||
Chan_(port_id)
|
||||
}
|
||||
|
||||
/// Constructs a port
|
||||
fn Port<T: send>() -> Port<T> {
|
||||
fn Port<T: Send>() -> Port<T> {
|
||||
Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
|
||||
}
|
||||
|
||||
impl<T: send> Port<T> {
|
||||
impl<T: Send> Port<T> {
|
||||
|
||||
fn chan() -> Chan<T> { Chan(self) }
|
||||
fn send(+v: T) { self.chan().send(v) }
|
||||
@@ -82,7 +82,7 @@ impl<T: send> Port<T> {
|
||||
|
||||
}
|
||||
|
||||
impl<T: send> Chan<T> {
|
||||
impl<T: Send> Chan<T> {
|
||||
|
||||
fn chan() -> Chan<T> { self }
|
||||
fn send(+v: T) { send(self, v) }
|
||||
@@ -92,12 +92,12 @@ impl<T: send> Chan<T> {
|
||||
}
|
||||
|
||||
/// Open a new receiving channel for the duration of a function
|
||||
fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
|
||||
fn listen<T: Send, U>(f: fn(Chan<T>) -> U) -> U {
|
||||
let po = Port();
|
||||
f(po.chan())
|
||||
}
|
||||
|
||||
struct PortPtr<T:send> {
|
||||
struct PortPtr<T:Send> {
|
||||
po: *rust_port,
|
||||
drop unsafe {
|
||||
do task::unkillable {
|
||||
@@ -121,7 +121,7 @@ struct PortPtr<T:send> {
|
||||
}
|
||||
}
|
||||
|
||||
fn PortPtr<T: send>(po: *rust_port) -> PortPtr<T> {
|
||||
fn PortPtr<T: Send>(po: *rust_port) -> PortPtr<T> {
|
||||
PortPtr {
|
||||
po: po
|
||||
}
|
||||
@@ -135,7 +135,7 @@ fn PortPtr<T: send>(po: *rust_port) -> PortPtr<T> {
|
||||
* Fails if the port is detached or dead. Fails if the port
|
||||
* is owned by a different task.
|
||||
*/
|
||||
fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
|
||||
fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
|
||||
|
||||
struct PortRef {
|
||||
p: *rust_port,
|
||||
@@ -167,7 +167,7 @@ fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
|
||||
* Constructs a channel. The channel is bound to the port used to
|
||||
* construct it.
|
||||
*/
|
||||
fn Chan<T: send>(p: Port<T>) -> Chan<T> {
|
||||
fn Chan<T: Send>(p: Port<T>) -> Chan<T> {
|
||||
Chan_(rustrt::get_port_id((**p).po))
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ fn Chan<T: send>(p: Port<T>) -> Chan<T> {
|
||||
* Sends data over a channel. The sent data is moved into the channel,
|
||||
* whereupon the caller loses access to it.
|
||||
*/
|
||||
fn send<T: send>(ch: Chan<T>, +data: T) {
|
||||
fn send<T: Send>(ch: Chan<T>, +data: T) {
|
||||
let Chan_(p) = ch;
|
||||
let data_ptr = ptr::addr_of(data) as *();
|
||||
let res = rustrt::rust_port_id_send(p, data_ptr);
|
||||
@@ -190,22 +190,22 @@ fn send<T: send>(ch: Chan<T>, +data: T) {
|
||||
* Receive from a port. If no data is available on the port then the
|
||||
* task will block until data becomes available.
|
||||
*/
|
||||
fn recv<T: send>(p: Port<T>) -> T { recv_((**p).po) }
|
||||
fn recv<T: Send>(p: Port<T>) -> T { recv_((**p).po) }
|
||||
|
||||
/// Returns true if there are messages available
|
||||
fn peek<T: send>(p: Port<T>) -> bool { peek_((**p).po) }
|
||||
fn peek<T: Send>(p: Port<T>) -> bool { peek_((**p).po) }
|
||||
|
||||
#[doc(hidden)]
|
||||
fn recv_chan<T: send>(ch: comm::Chan<T>) -> T {
|
||||
fn recv_chan<T: Send>(ch: comm::Chan<T>) -> T {
|
||||
as_raw_port(ch, |x|recv_(x))
|
||||
}
|
||||
|
||||
fn peek_chan<T: send>(ch: comm::Chan<T>) -> bool {
|
||||
fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
|
||||
as_raw_port(ch, |x|peek_(x))
|
||||
}
|
||||
|
||||
/// Receive on a raw port pointer
|
||||
fn recv_<T: send>(p: *rust_port) -> T {
|
||||
fn recv_<T: Send>(p: *rust_port) -> T {
|
||||
let yield = 0u;
|
||||
let yieldp = ptr::addr_of(yield);
|
||||
let mut res;
|
||||
@@ -231,7 +231,7 @@ fn peek_(p: *rust_port) -> bool {
|
||||
}
|
||||
|
||||
/// Receive on one of two ports
|
||||
fn select2<A: send, B: send>(p_a: Port<A>, p_b: Port<B>)
|
||||
fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
|
||||
-> Either<A, B> {
|
||||
let ports = ~[(**p_a).po, (**p_b).po];
|
||||
let yield = 0u, yieldp = ptr::addr_of(yield);
|
||||
|
||||
@@ -96,7 +96,7 @@ pure fn from_elem<T>(+data: T) -> DList<T> {
|
||||
list
|
||||
}
|
||||
|
||||
fn from_vec<T: copy>(+vec: &[T]) -> DList<T> {
|
||||
fn from_vec<T: Copy>(+vec: &[T]) -> DList<T> {
|
||||
do vec::foldl(DList(), vec) |list,data| {
|
||||
list.push(data); // Iterating left-to-right -- add newly to the tail.
|
||||
list
|
||||
@@ -417,7 +417,7 @@ impl<T> DList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: copy> DList<T> {
|
||||
impl<T: Copy> DList<T> {
|
||||
/// Remove data from the head of the list. O(1).
|
||||
fn pop() -> Option<T> { self.pop_n().map (|nobe| nobe.data) }
|
||||
/// Remove data from the tail of the list. O(1).
|
||||
|
||||
@@ -210,7 +210,7 @@ impl<A> DVec<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: copy> DVec<A> {
|
||||
impl<A: Copy> DVec<A> {
|
||||
/**
|
||||
* Append all elements of a vector to the end of the list
|
||||
*
|
||||
@@ -327,7 +327,7 @@ impl<A: copy> DVec<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A:copy> DVec<A>: Index<uint,A> {
|
||||
impl<A:Copy> DVec<A>: Index<uint,A> {
|
||||
pure fn index(&&idx: uint) -> A {
|
||||
self.get_elt(idx)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ fn either<T, U, V>(f_left: fn((&T)) -> V,
|
||||
}
|
||||
}
|
||||
|
||||
fn lefts<T: copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
|
||||
fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
|
||||
//! Extracts from a vector of either all the left values
|
||||
|
||||
let mut result: ~[T] = ~[];
|
||||
@@ -42,7 +42,7 @@ fn lefts<T: copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn rights<T, U: copy>(eithers: &[Either<T, U>]) -> ~[U] {
|
||||
fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
|
||||
//! Extracts from a vector of either all the right values
|
||||
|
||||
let mut result: ~[U] = ~[];
|
||||
@@ -55,7 +55,7 @@ fn rights<T, U: copy>(eithers: &[Either<T, U>]) -> ~[U] {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn partition<T: copy, U: copy>(eithers: &[Either<T, U>])
|
||||
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
|
||||
-> {lefts: ~[T], rights: ~[U]} {
|
||||
/*!
|
||||
* Extracts from a vector of either all the left values and right values
|
||||
@@ -75,7 +75,7 @@ fn partition<T: copy, U: copy>(eithers: &[Either<T, U>])
|
||||
return {lefts: lefts, rights: rights};
|
||||
}
|
||||
|
||||
pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> {
|
||||
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
|
||||
//! Flips between left and right of a given either
|
||||
|
||||
match *eith {
|
||||
@@ -84,7 +84,7 @@ pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> Result<U, T> {
|
||||
pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>) -> Result<U, T> {
|
||||
/*!
|
||||
* Converts either::t to a result::t
|
||||
*
|
||||
|
||||
@@ -43,7 +43,7 @@ priv enum FutureState<A> {
|
||||
}
|
||||
|
||||
/// Methods on the `future` type
|
||||
impl<A:copy> Future<A> {
|
||||
impl<A:Copy> Future<A> {
|
||||
fn get() -> A {
|
||||
//! Get the value of the future
|
||||
|
||||
@@ -74,7 +74,7 @@ fn from_value<A>(+val: A) -> Future<A> {
|
||||
Future {state: Forced(val)}
|
||||
}
|
||||
|
||||
fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
|
||||
fn from_port<A:Send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
|
||||
/*!
|
||||
* Create a future from a port
|
||||
*
|
||||
@@ -105,7 +105,7 @@ fn from_fn<A>(+f: @fn() -> A) -> Future<A> {
|
||||
Future {state: Pending(f)}
|
||||
}
|
||||
|
||||
fn spawn<A:send>(+blk: fn~() -> A) -> Future<A> {
|
||||
fn spawn<A:Send>(+blk: fn~() -> A) -> Future<A> {
|
||||
/*!
|
||||
* Create a future from a unique closure.
|
||||
*
|
||||
@@ -156,7 +156,7 @@ fn get_ref<A>(future: &r/Future<A>) -> &r/A {
|
||||
}
|
||||
}
|
||||
|
||||
fn get<A:copy>(future: &Future<A>) -> A {
|
||||
fn get<A:Copy>(future: &Future<A>) -> A {
|
||||
//! Get the value of the future
|
||||
|
||||
*get_ref(future)
|
||||
@@ -169,7 +169,7 @@ fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
|
||||
}
|
||||
|
||||
proto! future_pipe (
|
||||
waiting:recv<T:send> {
|
||||
waiting:recv<T:Send> {
|
||||
completed(T) -> !
|
||||
}
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> {
|
||||
impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
|
||||
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> {
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
||||
}
|
||||
|
||||
impl<A: copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {
|
||||
impl<A: Copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {
|
||||
pure fn min() -> A { iter::min(self) }
|
||||
pure fn max() -> A { iter::max(self) }
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ trait TimesIx{
|
||||
pure fn timesi(it: fn(uint) -> bool);
|
||||
}
|
||||
|
||||
trait CopyableIter<A:copy> {
|
||||
trait CopyableIter<A:Copy> {
|
||||
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A];
|
||||
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
|
||||
pure fn to_vec() -> ~[A];
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A>;
|
||||
}
|
||||
|
||||
trait CopyableOrderedIter<A:copy Ord> {
|
||||
trait CopyableOrderedIter<A:Copy Ord> {
|
||||
pure fn min() -> A;
|
||||
pure fn max() -> A;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ pure fn any<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pure fn filter_to_vec<A:copy,IA:BaseIter<A>>(self: IA,
|
||||
pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: IA,
|
||||
prd: fn(A) -> bool) -> ~[A] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
@@ -91,7 +91,7 @@ pure fn filter_to_vec<A:copy,IA:BaseIter<A>>(self: IA,
|
||||
}
|
||||
}
|
||||
|
||||
pure fn map_to_vec<A:copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
|
||||
pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
|
||||
-> ~[B] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
@@ -100,7 +100,7 @@ pure fn map_to_vec<A:copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
|
||||
}
|
||||
}
|
||||
|
||||
pure fn flat_map_to_vec<A:copy,B:copy,IA:BaseIter<A>,IB:BaseIter<B>>(
|
||||
pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
|
||||
self: IA, op: fn(A) -> IB) -> ~[B] {
|
||||
|
||||
do vec::build |push| {
|
||||
@@ -120,7 +120,7 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
|
||||
return b;
|
||||
}
|
||||
|
||||
pure fn to_vec<A:copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
|
||||
pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
|
||||
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ pure fn repeat(times: uint, blk: fn() -> bool) {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn min<A:copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||
pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
Some(a_) if a_ < b => {
|
||||
@@ -179,7 +179,7 @@ pure fn min<A:copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A {
|
||||
pure fn max<A:Copy,IA:BaseIter<A>>(self: IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
Some(a_) if a_ > b => {
|
||||
@@ -195,7 +195,7 @@ pure fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn find<A: copy,IA:BaseIter<A>>(self: IA,
|
||||
pure fn find<A: Copy,IA:BaseIter<A>>(self: IA,
|
||||
p: fn(A) -> bool) -> Option<A> {
|
||||
for self.each |i| {
|
||||
if p(i) { return Some(i) }
|
||||
@@ -271,7 +271,7 @@ pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
pure fn from_elem<T: copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||
pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||
do build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts { push(t); i += 1u; }
|
||||
@@ -280,7 +280,7 @@ pure fn from_elem<T: copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||
|
||||
/// Appending two generic sequences
|
||||
#[inline(always)]
|
||||
pure fn append<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
||||
pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
||||
lhs: IT, rhs: IT) -> BT {
|
||||
let size_opt = lhs.size_hint().chain(
|
||||
|sz1| rhs.size_hint().map(|sz2| sz1+sz2));
|
||||
@@ -293,7 +293,7 @@ pure fn append<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
||||
/// Copies a generic sequence, possibly converting it to a different
|
||||
/// type of sequence.
|
||||
#[inline(always)]
|
||||
pure fn copy_seq<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
||||
pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
||||
v: IT) -> BT {
|
||||
do build_sized_opt(v.size_hint()) |push| {
|
||||
for v.each |x| { push(x); }
|
||||
|
||||
@@ -16,7 +16,7 @@ enum Option<T> {
|
||||
Some(T),
|
||||
}
|
||||
|
||||
pure fn get<T: copy>(opt: Option<T>) -> T {
|
||||
pure fn get<T: Copy>(opt: Option<T>) -> T {
|
||||
/*!
|
||||
* Gets the value out of an option
|
||||
*
|
||||
@@ -45,7 +45,7 @@ pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn expect<T: copy>(opt: Option<T>, reason: ~str) -> T {
|
||||
pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T {
|
||||
/*!
|
||||
* Gets the value out of an option, printing a specified message on
|
||||
* failure
|
||||
@@ -128,7 +128,7 @@ pure fn is_some<T>(opt: Option<T>) -> bool {
|
||||
!is_none(opt)
|
||||
}
|
||||
|
||||
pure fn get_default<T: copy>(opt: Option<T>, def: T) -> T {
|
||||
pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T {
|
||||
//! Returns the contained value or a default
|
||||
|
||||
match opt { Some(x) => x, None => def }
|
||||
@@ -226,7 +226,7 @@ impl<T> &Option<T> {
|
||||
pure fn get_ref() -> &self/T { get_ref(self) }
|
||||
}
|
||||
|
||||
impl<T: copy> Option<T> {
|
||||
impl<T: Copy> Option<T> {
|
||||
/**
|
||||
* Gets the value out of an option
|
||||
*
|
||||
|
||||
@@ -152,7 +152,7 @@ fn buffer_header() -> BufferHeader { BufferHeader() }
|
||||
|
||||
// This is for protocols to associate extra data to thread around.
|
||||
#[doc(hidden)]
|
||||
type Buffer<T: send> = {
|
||||
type Buffer<T: Send> = {
|
||||
header: BufferHeader,
|
||||
data: T,
|
||||
};
|
||||
@@ -191,7 +191,7 @@ struct PacketHeader {
|
||||
reinterpret_cast(&self.buffer)
|
||||
}
|
||||
|
||||
fn set_buffer<T: send>(b: ~Buffer<T>) unsafe {
|
||||
fn set_buffer<T: Send>(b: ~Buffer<T>) unsafe {
|
||||
self.buffer = reinterpret_cast(&b);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ fn PacketHeader() -> PacketHeader {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
type Packet<T: send> = {
|
||||
type Packet<T: Send> = {
|
||||
header: PacketHeader,
|
||||
mut payload: Option<T>,
|
||||
};
|
||||
@@ -213,7 +213,7 @@ type Packet<T: send> = {
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type packet<T: send> = Packet<T>;
|
||||
type packet<T: Send> = Packet<T>;
|
||||
|
||||
#[doc(hidden)]
|
||||
trait HasBuffer {
|
||||
@@ -221,7 +221,7 @@ trait HasBuffer {
|
||||
fn set_buffer_(b: *libc::c_void);
|
||||
}
|
||||
|
||||
impl<T: send> Packet<T>: HasBuffer {
|
||||
impl<T: Send> Packet<T>: HasBuffer {
|
||||
fn set_buffer_(b: *libc::c_void) {
|
||||
self.header.buffer = b;
|
||||
}
|
||||
@@ -235,14 +235,14 @@ trait has_buffer {
|
||||
}
|
||||
|
||||
#[cfg(stage0)] // XXX remove me
|
||||
impl<T: send> packet<T>: has_buffer {
|
||||
impl<T: Send> packet<T>: has_buffer {
|
||||
fn set_buffer(b: *libc::c_void) {
|
||||
self.header.buffer = b;
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn mk_packet<T: send>() -> Packet<T> {
|
||||
fn mk_packet<T: Send>() -> Packet<T> {
|
||||
{
|
||||
header: PacketHeader(),
|
||||
mut payload: None
|
||||
@@ -250,7 +250,7 @@ fn mk_packet<T: send>() -> Packet<T> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
|
||||
fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
|
||||
let b = ~{
|
||||
header: BufferHeader(),
|
||||
data: {
|
||||
@@ -267,7 +267,7 @@ fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn packet<T: send>() -> *Packet<T> {
|
||||
fn packet<T: Send>() -> *Packet<T> {
|
||||
let b = unibuffer();
|
||||
let p = ptr::addr_of(b.data);
|
||||
// We'll take over memory management from here.
|
||||
@@ -276,7 +276,7 @@ fn packet<T: send>() -> *Packet<T> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn entangle_buffer<T: send, Tstart: send>(
|
||||
fn entangle_buffer<T: Send, Tstart: Send>(
|
||||
+buffer: ~Buffer<T>,
|
||||
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
||||
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
||||
@@ -368,12 +368,12 @@ fn swap_state_rel(+dst: &mut State, src: State) -> State {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
unsafe fn get_buffer<T: send>(p: *PacketHeader) -> ~Buffer<T> {
|
||||
unsafe fn get_buffer<T: Send>(p: *PacketHeader) -> ~Buffer<T> {
|
||||
transmute((*p).buf_header())
|
||||
}
|
||||
|
||||
// This could probably be done with SharedMutableState to avoid move_it!().
|
||||
struct BufferResource<T: send> {
|
||||
struct BufferResource<T: Send> {
|
||||
buffer: ~Buffer<T>,
|
||||
|
||||
drop unsafe {
|
||||
@@ -393,7 +393,7 @@ struct BufferResource<T: send> {
|
||||
}
|
||||
}
|
||||
|
||||
fn BufferResource<T: send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
||||
fn BufferResource<T: Send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
||||
//let p = ptr::addr_of(*b);
|
||||
//error!("take %?", p);
|
||||
atomic_add_acq(&mut b.header.ref_count, 1);
|
||||
@@ -404,7 +404,7 @@ fn BufferResource<T: send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn send<T: send, Tbuffer: send>(+p: SendPacketBuffered<T, Tbuffer>,
|
||||
fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
|
||||
+payload: T) -> bool {
|
||||
let header = p.header();
|
||||
let p_ = p.unwrap();
|
||||
@@ -448,7 +448,7 @@ fn send<T: send, Tbuffer: send>(+p: SendPacketBuffered<T, Tbuffer>,
|
||||
Fails if the sender closes the connection.
|
||||
|
||||
*/
|
||||
fn recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
||||
fn recv<T: Send, Tbuffer: Send>(+p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
||||
option::unwrap_expect(try_recv(p), "connection closed")
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ Returns `none` if the sender has closed the connection without sending
|
||||
a message, or `Some(T)` if a message was received.
|
||||
|
||||
*/
|
||||
fn try_recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>)
|
||||
fn try_recv<T: Send, Tbuffer: Send>(+p: RecvPacketBuffered<T, Tbuffer>)
|
||||
-> Option<T>
|
||||
{
|
||||
let p_ = p.unwrap();
|
||||
@@ -552,7 +552,7 @@ fn try_recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>)
|
||||
}
|
||||
|
||||
/// Returns true if messages are available.
|
||||
pure fn peek<T: send, Tb: send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
||||
pure fn peek<T: Send, Tb: Send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
||||
match unsafe {(*p.header()).state} {
|
||||
Empty => false,
|
||||
Blocked => fail ~"peeking on blocked packet",
|
||||
@@ -560,14 +560,14 @@ pure fn peek<T: send, Tb: send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: send, Tb: send> RecvPacketBuffered<T, Tb> {
|
||||
impl<T: Send, Tb: Send> RecvPacketBuffered<T, Tb> {
|
||||
pure fn peek() -> bool {
|
||||
peek(&self)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn sender_terminate<T: send>(p: *Packet<T>) {
|
||||
fn sender_terminate<T: Send>(p: *Packet<T>) {
|
||||
let p = unsafe { &*p };
|
||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||
Empty => {
|
||||
@@ -596,7 +596,7 @@ fn sender_terminate<T: send>(p: *Packet<T>) {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn receiver_terminate<T: send>(p: *Packet<T>) {
|
||||
fn receiver_terminate<T: Send>(p: *Packet<T>) {
|
||||
let p = unsafe { &*p };
|
||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||
Empty => {
|
||||
@@ -704,7 +704,7 @@ Sometimes messages will be available on both endpoints at once. In
|
||||
this case, `select2` may return either `left` or `right`.
|
||||
|
||||
*/
|
||||
fn select2<A: send, Ab: send, B: send, Bb: send>(
|
||||
fn select2<A: Send, Ab: Send, B: Send, Bb: Send>(
|
||||
+a: RecvPacketBuffered<A, Ab>,
|
||||
+b: RecvPacketBuffered<B, Bb>)
|
||||
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
|
||||
@@ -746,7 +746,7 @@ fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) -> Either<(), ()> {
|
||||
list of the remaining endpoints.
|
||||
|
||||
*/
|
||||
fn select<T: send, Tb: send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||
fn select<T: Send, Tb: Send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
||||
{
|
||||
let ready = wait_many(endpoints.map(|p| p.header()));
|
||||
@@ -760,25 +760,25 @@ fn select<T: send, Tb: send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||
message.
|
||||
|
||||
*/
|
||||
type SendPacket<T: send> = SendPacketBuffered<T, Packet<T>>;
|
||||
type SendPacket<T: Send> = SendPacketBuffered<T, Packet<T>>;
|
||||
|
||||
#[doc(hidden)]
|
||||
fn SendPacket<T: send>(p: *Packet<T>) -> SendPacket<T> {
|
||||
fn SendPacket<T: Send>(p: *Packet<T>) -> SendPacket<T> {
|
||||
SendPacketBuffered(p)
|
||||
}
|
||||
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type send_packet<T: send> = SendPacket<T>;
|
||||
type send_packet<T: Send> = SendPacket<T>;
|
||||
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
fn send_packet<T: send>(p: *packet<T>) -> SendPacket<T> {
|
||||
fn send_packet<T: Send>(p: *packet<T>) -> SendPacket<T> {
|
||||
SendPacket(p)
|
||||
}
|
||||
|
||||
struct SendPacketBuffered<T: send, Tbuffer: send> {
|
||||
struct SendPacketBuffered<T: Send, Tbuffer: Send> {
|
||||
mut p: Option<*Packet<T>>,
|
||||
mut buffer: Option<BufferResource<Tbuffer>>,
|
||||
drop {
|
||||
@@ -821,7 +821,7 @@ struct SendPacketBuffered<T: send, Tbuffer: send> {
|
||||
}
|
||||
}
|
||||
|
||||
fn SendPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
||||
fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
||||
-> SendPacketBuffered<T, Tbuffer> {
|
||||
//debug!("take send %?", p);
|
||||
SendPacketBuffered {
|
||||
@@ -836,30 +836,30 @@ fn SendPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type send_packet_buffered<T: send, Tbuffer: send> =
|
||||
type send_packet_buffered<T: Send, Tbuffer: Send> =
|
||||
SendPacketBuffered<T, Tbuffer>;
|
||||
|
||||
/// Represents the receive end of a pipe. It can receive exactly one
|
||||
/// message.
|
||||
type RecvPacket<T: send> = RecvPacketBuffered<T, Packet<T>>;
|
||||
type RecvPacket<T: Send> = RecvPacketBuffered<T, Packet<T>>;
|
||||
|
||||
#[doc(hidden)]
|
||||
fn RecvPacket<T: send>(p: *Packet<T>) -> RecvPacket<T> {
|
||||
fn RecvPacket<T: Send>(p: *Packet<T>) -> RecvPacket<T> {
|
||||
RecvPacketBuffered(p)
|
||||
}
|
||||
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type recv_packet<T: send> = RecvPacket<T>;
|
||||
type recv_packet<T: Send> = RecvPacket<T>;
|
||||
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
fn recv_packet<T: send>(p: *packet<T>) -> RecvPacket<T> {
|
||||
fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
|
||||
RecvPacket(p)
|
||||
}
|
||||
|
||||
struct RecvPacketBuffered<T: send, Tbuffer: send> : Selectable {
|
||||
struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
|
||||
mut p: Option<*Packet<T>>,
|
||||
mut buffer: Option<BufferResource<Tbuffer>>,
|
||||
drop {
|
||||
@@ -902,7 +902,7 @@ struct RecvPacketBuffered<T: send, Tbuffer: send> : Selectable {
|
||||
}
|
||||
}
|
||||
|
||||
fn RecvPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
||||
fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
||||
-> RecvPacketBuffered<T, Tbuffer> {
|
||||
//debug!("take recv %?", p);
|
||||
RecvPacketBuffered {
|
||||
@@ -917,11 +917,11 @@ fn RecvPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
||||
// XXX remove me
|
||||
#[cfg(stage0)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type recv_packet_buffered<T: send, Tbuffer: send> =
|
||||
type recv_packet_buffered<T: Send, Tbuffer: Send> =
|
||||
RecvPacketBuffered<T, Tbuffer>;
|
||||
|
||||
#[doc(hidden)]
|
||||
fn entangle<T: send>() -> (SendPacket<T>, RecvPacket<T>) {
|
||||
fn entangle<T: Send>() -> (SendPacket<T>, RecvPacket<T>) {
|
||||
let p = packet();
|
||||
(SendPacket(p), RecvPacket(p))
|
||||
}
|
||||
@@ -933,7 +933,7 @@ endpoint. The send endpoint is returned to the caller and the receive
|
||||
endpoint is passed to the new task.
|
||||
|
||||
*/
|
||||
fn spawn_service<T: send, Tb: send>(
|
||||
fn spawn_service<T: Send, Tb: Send>(
|
||||
init: extern fn() -> (SendPacketBuffered<T, Tb>,
|
||||
RecvPacketBuffered<T, Tb>),
|
||||
+service: fn~(+RecvPacketBuffered<T, Tb>))
|
||||
@@ -957,7 +957,7 @@ fn spawn_service<T: send, Tb: send>(
|
||||
receive state.
|
||||
|
||||
*/
|
||||
fn spawn_service_recv<T: send, Tb: send>(
|
||||
fn spawn_service_recv<T: Send, Tb: Send>(
|
||||
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
|
||||
SendPacketBuffered<T, Tb>),
|
||||
+service: fn~(+SendPacketBuffered<T, Tb>))
|
||||
@@ -980,13 +980,13 @@ fn spawn_service_recv<T: send, Tb: send>(
|
||||
// Streams - Make pipes a little easier in general.
|
||||
|
||||
proto! streamp (
|
||||
Open:send<T: send> {
|
||||
Open:send<T: Send> {
|
||||
data(T) -> Open<T>
|
||||
}
|
||||
)
|
||||
|
||||
/// A trait for things that can send multiple messages.
|
||||
trait Channel<T: send> {
|
||||
trait Channel<T: Send> {
|
||||
// It'd be nice to call this send, but it'd conflict with the
|
||||
// built in send kind.
|
||||
|
||||
@@ -998,7 +998,7 @@ trait Channel<T: send> {
|
||||
}
|
||||
|
||||
/// A trait for things that can receive multiple messages.
|
||||
trait Recv<T: send> {
|
||||
trait Recv<T: Send> {
|
||||
/// Receives a message, or fails if the connection closes.
|
||||
fn recv() -> T;
|
||||
|
||||
@@ -1016,18 +1016,18 @@ trait Recv<T: send> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
type Chan_<T:send> = { mut endp: Option<streamp::client::Open<T>> };
|
||||
type Chan_<T:Send> = { mut endp: Option<streamp::client::Open<T>> };
|
||||
|
||||
/// An endpoint that can send many messages.
|
||||
enum Chan<T:send> {
|
||||
enum Chan<T:Send> {
|
||||
Chan_(Chan_<T>)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
type Port_<T:send> = { mut endp: Option<streamp::server::Open<T>> };
|
||||
type Port_<T:Send> = { mut endp: Option<streamp::server::Open<T>> };
|
||||
|
||||
/// An endpoint that can receive many messages.
|
||||
enum Port<T:send> {
|
||||
enum Port<T:Send> {
|
||||
Port_(Port_<T>)
|
||||
}
|
||||
|
||||
@@ -1036,13 +1036,13 @@ enum Port<T:send> {
|
||||
These allow sending or receiving an unlimited number of messages.
|
||||
|
||||
*/
|
||||
fn stream<T:send>() -> (Chan<T>, Port<T>) {
|
||||
fn stream<T:Send>() -> (Chan<T>, Port<T>) {
|
||||
let (c, s) = streamp::init();
|
||||
|
||||
(Chan_({ mut endp: Some(c) }), Port_({ mut endp: Some(s) }))
|
||||
}
|
||||
|
||||
impl<T: send> Chan<T>: Channel<T> {
|
||||
impl<T: Send> Chan<T>: Channel<T> {
|
||||
fn send(+x: T) {
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
@@ -1063,7 +1063,7 @@ impl<T: send> Chan<T>: Channel<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: send> Port<T>: Recv<T> {
|
||||
impl<T: Send> Port<T>: Recv<T> {
|
||||
fn recv() -> T {
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
@@ -1097,7 +1097,7 @@ impl<T: send> Port<T>: Recv<T> {
|
||||
}
|
||||
|
||||
/// Treat many ports as one.
|
||||
struct PortSet<T: send> : Recv<T> {
|
||||
struct PortSet<T: Send> : Recv<T> {
|
||||
mut ports: ~[pipes::Port<T>],
|
||||
|
||||
fn add(+port: pipes::Port<T>) {
|
||||
@@ -1146,13 +1146,13 @@ struct PortSet<T: send> : Recv<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn PortSet<T: send>() -> PortSet<T>{
|
||||
fn PortSet<T: Send>() -> PortSet<T>{
|
||||
PortSet {
|
||||
ports: ~[]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: send> Port<T>: Selectable {
|
||||
impl<T: Send> Port<T>: Selectable {
|
||||
pure fn header() -> *PacketHeader unchecked {
|
||||
match self.endp {
|
||||
Some(endp) => endp.header(),
|
||||
@@ -1162,9 +1162,9 @@ impl<T: send> Port<T>: Selectable {
|
||||
}
|
||||
|
||||
/// A channel that can be shared between many senders.
|
||||
type SharedChan<T: send> = unsafe::Exclusive<Chan<T>>;
|
||||
type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;
|
||||
|
||||
impl<T: send> SharedChan<T>: Channel<T> {
|
||||
impl<T: Send> SharedChan<T>: Channel<T> {
|
||||
fn send(+x: T) {
|
||||
let mut xx = Some(x);
|
||||
do self.with |chan| {
|
||||
@@ -1185,19 +1185,19 @@ impl<T: send> SharedChan<T>: Channel<T> {
|
||||
}
|
||||
|
||||
/// Converts a `chan` into a `shared_chan`.
|
||||
fn SharedChan<T:send>(+c: Chan<T>) -> SharedChan<T> {
|
||||
fn SharedChan<T:Send>(+c: Chan<T>) -> SharedChan<T> {
|
||||
unsafe::exclusive(c)
|
||||
}
|
||||
|
||||
/// Receive a message from one of two endpoints.
|
||||
trait Select2<T: send, U: send> {
|
||||
trait Select2<T: Send, U: Send> {
|
||||
/// Receive a message or return `none` if a connection closes.
|
||||
fn try_select() -> Either<Option<T>, Option<U>>;
|
||||
/// Receive a message or fail if a connection closes.
|
||||
fn select() -> Either<T, U>;
|
||||
}
|
||||
|
||||
impl<T: send, U: send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
||||
impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
||||
(Left, Right): Select2<T, U> {
|
||||
|
||||
fn select() -> Either<T, U> {
|
||||
@@ -1220,18 +1220,18 @@ impl<T: send, U: send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
||||
}
|
||||
|
||||
proto! oneshot (
|
||||
Oneshot:send<T:send> {
|
||||
Oneshot:send<T:Send> {
|
||||
send(T) -> !
|
||||
}
|
||||
)
|
||||
|
||||
/// The send end of a oneshot pipe.
|
||||
type ChanOne<T: send> = oneshot::client::Oneshot<T>;
|
||||
type ChanOne<T: Send> = oneshot::client::Oneshot<T>;
|
||||
/// The receive end of a oneshot pipe.
|
||||
type PortOne<T: send> = oneshot::server::Oneshot<T>;
|
||||
type PortOne<T: Send> = oneshot::server::Oneshot<T>;
|
||||
|
||||
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
|
||||
fn oneshot<T: send>() -> (ChanOne<T>, PortOne<T>) {
|
||||
fn oneshot<T: Send>() -> (ChanOne<T>, PortOne<T>) {
|
||||
oneshot::init()
|
||||
}
|
||||
|
||||
@@ -1239,13 +1239,13 @@ fn oneshot<T: send>() -> (ChanOne<T>, PortOne<T>) {
|
||||
* Receive a message from a oneshot pipe, failing if the connection was
|
||||
* closed.
|
||||
*/
|
||||
fn recv_one<T: send>(+port: PortOne<T>) -> T {
|
||||
fn recv_one<T: Send>(+port: PortOne<T>) -> T {
|
||||
let oneshot::send(message) = recv(port);
|
||||
message
|
||||
}
|
||||
|
||||
/// Receive a message from a oneshot pipe unless the connection was closed.
|
||||
fn try_recv_one<T: send> (+port: PortOne<T>) -> Option<T> {
|
||||
fn try_recv_one<T: Send> (+port: PortOne<T>) -> Option<T> {
|
||||
let message = try_recv(port);
|
||||
|
||||
if message.is_none() { None }
|
||||
@@ -1256,7 +1256,7 @@ fn try_recv_one<T: send> (+port: PortOne<T>) -> Option<T> {
|
||||
}
|
||||
|
||||
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
||||
fn send_one<T: send>(+chan: ChanOne<T>, +data: T) {
|
||||
fn send_one<T: Send>(+chan: ChanOne<T>, +data: T) {
|
||||
oneshot::client::send(chan, data);
|
||||
}
|
||||
|
||||
@@ -1264,7 +1264,7 @@ fn send_one<T: send>(+chan: ChanOne<T>, +data: T) {
|
||||
* Send a message on a oneshot pipe, or return false if the connection was
|
||||
* closed.
|
||||
*/
|
||||
fn try_send_one<T: send>(+chan: ChanOne<T>, +data: T)
|
||||
fn try_send_one<T: Send>(+chan: ChanOne<T>, +data: T)
|
||||
-> bool {
|
||||
oneshot::client::try_send(chan, data).is_some()
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type GlobalPtr = *libc::uintptr_t;
|
||||
* or, if no channel exists creates and installs a new channel and sets up a
|
||||
* new task to receive from it.
|
||||
*/
|
||||
unsafe fn chan_from_global_ptr<T: send>(
|
||||
unsafe fn chan_from_global_ptr<T: Send>(
|
||||
global: GlobalPtr,
|
||||
task_fn: fn() -> task::TaskBuilder,
|
||||
+f: fn~(comm::Port<T>)
|
||||
|
||||
@@ -165,12 +165,12 @@ impl Rng {
|
||||
}
|
||||
|
||||
/// Choose an item randomly, failing if values is empty
|
||||
fn choose<T:copy>(values: &[T]) -> T {
|
||||
fn choose<T:Copy>(values: &[T]) -> T {
|
||||
self.choose_option(values).get()
|
||||
}
|
||||
|
||||
/// Choose Some(item) randomly, returning None if values is empty
|
||||
fn choose_option<T:copy>(values: &[T]) -> Option<T> {
|
||||
fn choose_option<T:Copy>(values: &[T]) -> Option<T> {
|
||||
if values.is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -182,7 +182,7 @@ impl Rng {
|
||||
* Choose an item respecting the relative weights, failing if the sum of
|
||||
* the weights is 0
|
||||
*/
|
||||
fn choose_weighted<T: copy>(v : &[Weighted<T>]) -> T {
|
||||
fn choose_weighted<T: Copy>(v : &[Weighted<T>]) -> T {
|
||||
self.choose_weighted_option(v).get()
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ impl Rng {
|
||||
* Choose Some(item) respecting the relative weights, returning none if
|
||||
* the sum of the weights is 0
|
||||
*/
|
||||
fn choose_weighted_option<T:copy>(v: &[Weighted<T>]) -> Option<T> {
|
||||
fn choose_weighted_option<T:Copy>(v: &[Weighted<T>]) -> Option<T> {
|
||||
let mut total = 0u;
|
||||
for v.each |item| {
|
||||
total += item.weight;
|
||||
@@ -213,7 +213,7 @@ impl Rng {
|
||||
* Return a vec containing copies of the items, in order, where
|
||||
* the weight of the item determines how many copies there are
|
||||
*/
|
||||
fn weighted_vec<T:copy>(v: &[Weighted<T>]) -> ~[T] {
|
||||
fn weighted_vec<T:Copy>(v: &[Weighted<T>]) -> ~[T] {
|
||||
let mut r = ~[];
|
||||
for v.each |item| {
|
||||
for uint::range(0u, item.weight) |_i| {
|
||||
@@ -224,7 +224,7 @@ impl Rng {
|
||||
}
|
||||
|
||||
/// Shuffle a vec
|
||||
fn shuffle<T:copy>(values: &[T]) -> ~[T] {
|
||||
fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
|
||||
let mut m = vec::from_slice(values);
|
||||
self.shuffle_mut(m);
|
||||
return m;
|
||||
|
||||
@@ -18,7 +18,7 @@ enum Result<T, U> {
|
||||
*
|
||||
* If the result is an error
|
||||
*/
|
||||
pure fn get<T: copy, U>(res: Result<T, U>) -> T {
|
||||
pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
|
||||
match res {
|
||||
Ok(t) => t,
|
||||
Err(the_err) => unchecked {
|
||||
@@ -50,7 +50,7 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
||||
*
|
||||
* If the result is not an error
|
||||
*/
|
||||
pure fn get_err<T, U: copy>(res: Result<T, U>) -> U {
|
||||
pure fn get_err<T, U: Copy>(res: Result<T, U>) -> U {
|
||||
match res {
|
||||
Err(u) => u,
|
||||
Ok(_) => fail ~"get_err called on ok result"
|
||||
@@ -76,7 +76,7 @@ pure fn is_err<T, U>(res: Result<T, U>) -> bool {
|
||||
* `ok` result variants are converted to `either::right` variants, `err`
|
||||
* result variants are converted to `either::left`.
|
||||
*/
|
||||
pure fn to_either<T: copy, U: copy>(res: Result<U, T>) -> Either<T, U> {
|
||||
pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> {
|
||||
match res {
|
||||
Ok(res) => either::Right(res),
|
||||
Err(fail_) => either::Left(fail_)
|
||||
@@ -97,7 +97,7 @@ pure fn to_either<T: copy, U: copy>(res: Result<U, T>) -> Either<T, U> {
|
||||
* ok(parse_buf(buf))
|
||||
* }
|
||||
*/
|
||||
fn chain<T, U: copy, V: copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
|
||||
fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
|
||||
-> Result<U, V> {
|
||||
match res {
|
||||
Ok(t) => op(t),
|
||||
@@ -113,7 +113,7 @@ fn chain<T, U: copy, V: copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
|
||||
* immediately returned. This function can be used to pass through a
|
||||
* successful result while handling an error.
|
||||
*/
|
||||
fn chain_err<T: copy, U: copy, V: copy>(
|
||||
fn chain_err<T: Copy, U: Copy, V: Copy>(
|
||||
res: Result<T, V>,
|
||||
op: fn(V) -> Result<T, U>)
|
||||
-> Result<T, U> {
|
||||
@@ -173,7 +173,7 @@ fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
|
||||
* parse_buf(buf)
|
||||
* }
|
||||
*/
|
||||
fn map<T, E: copy, U: copy>(res: Result<T, E>, op: fn(T) -> U)
|
||||
fn map<T, E: Copy, U: Copy>(res: Result<T, E>, op: fn(T) -> U)
|
||||
-> Result<U, E> {
|
||||
match res {
|
||||
Ok(t) => Ok(op(t)),
|
||||
@@ -189,7 +189,7 @@ fn map<T, E: copy, U: copy>(res: Result<T, E>, op: fn(T) -> U)
|
||||
* is immediately returned. This function can be used to pass through a
|
||||
* successful result while handling an error.
|
||||
*/
|
||||
fn map_err<T: copy, E, F: copy>(res: Result<T, E>, op: fn(E) -> F)
|
||||
fn map_err<T: Copy, E, F: Copy>(res: Result<T, E>, op: fn(E) -> F)
|
||||
-> Result<T, F> {
|
||||
match res {
|
||||
Ok(t) => Ok(t),
|
||||
@@ -217,10 +217,10 @@ impl<T, E> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: copy, E> Result<T, E> {
|
||||
impl<T: Copy, E> Result<T, E> {
|
||||
fn get() -> T { get(self) }
|
||||
|
||||
fn map_err<F:copy>(op: fn(E) -> F) -> Result<T,F> {
|
||||
fn map_err<F:Copy>(op: fn(E) -> F) -> Result<T,F> {
|
||||
match self {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(op(e))
|
||||
@@ -228,10 +228,10 @@ impl<T: copy, E> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E: copy> Result<T, E> {
|
||||
impl<T, E: Copy> Result<T, E> {
|
||||
fn get_err() -> E { get_err(self) }
|
||||
|
||||
fn map<U:copy>(op: fn(T) -> U) -> Result<U,E> {
|
||||
fn map<U:Copy>(op: fn(T) -> U) -> Result<U,E> {
|
||||
match self {
|
||||
Ok(t) => Ok(op(t)),
|
||||
Err(e) => Err(e)
|
||||
@@ -239,12 +239,12 @@ impl<T, E: copy> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: copy, E: copy> Result<T, E> {
|
||||
fn chain<U:copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||
impl<T: Copy, E: Copy> Result<T, E> {
|
||||
fn chain<U:Copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||
chain(self, op)
|
||||
}
|
||||
|
||||
fn chain_err<F:copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||
fn chain_err<F:Copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||
chain_err(self, op)
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,7 @@ impl<T: copy, E: copy> Result<T, E> {
|
||||
* assert incd == ~[2u, 3u, 4u];
|
||||
* }
|
||||
*/
|
||||
fn map_vec<T,U:copy,V:copy>(
|
||||
fn map_vec<T,U:Copy,V:Copy>(
|
||||
ts: &[T], op: fn(T) -> Result<V,U>) -> Result<~[V],U> {
|
||||
|
||||
let mut vs: ~[V] = ~[];
|
||||
@@ -280,7 +280,7 @@ fn map_vec<T,U:copy,V:copy>(
|
||||
return Ok(vs);
|
||||
}
|
||||
|
||||
fn map_opt<T,U:copy,V:copy>(
|
||||
fn map_opt<T,U:Copy,V:Copy>(
|
||||
o_t: Option<T>, op: fn(T) -> Result<V,U>) -> Result<Option<V>,U> {
|
||||
|
||||
match o_t {
|
||||
@@ -301,7 +301,7 @@ fn map_opt<T,U:copy,V:copy>(
|
||||
* used in 'careful' code contexts where it is both appropriate and easy
|
||||
* to accommodate an error like the vectors being of different lengths.
|
||||
*/
|
||||
fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T],
|
||||
fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
|
||||
op: fn(S,T) -> Result<V,U>) -> Result<~[V],U> {
|
||||
|
||||
assert vec::same_length(ss, ts);
|
||||
@@ -324,7 +324,7 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T],
|
||||
* error. This could be implemented using `map2()` but it is more efficient
|
||||
* on its own as no result vector is built.
|
||||
*/
|
||||
fn iter_vec2<S,T,U:copy>(ss: &[S], ts: &[T],
|
||||
fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
||||
op: fn(S,T) -> Result<(),U>) -> Result<(),U> {
|
||||
|
||||
assert vec::same_length(ss, ts);
|
||||
|
||||
@@ -8,7 +8,7 @@ use cmp::Eq;
|
||||
use hash::Hash;
|
||||
use to_bytes::IterBytes;
|
||||
|
||||
trait SendMap<K:Eq Hash, V: copy> {
|
||||
trait SendMap<K:Eq Hash, V: Copy> {
|
||||
// FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy
|
||||
|
||||
fn insert(&mut self, +k: K, +v: V) -> bool;
|
||||
@@ -315,7 +315,7 @@ mod linear {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Hash IterBytes Eq, V: copy> LinearMap<K,V> {
|
||||
impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
|
||||
fn find(&const self, k: &K) -> Option<V> {
|
||||
match self.bucket_for_key(self.buckets, k) {
|
||||
FoundEntry(idx) => {
|
||||
@@ -342,17 +342,17 @@ mod linear {
|
||||
|
||||
}
|
||||
|
||||
impl<K: Hash IterBytes Eq copy, V: copy> LinearMap<K,V> {
|
||||
impl<K: Hash IterBytes Eq Copy, V: Copy> LinearMap<K,V> {
|
||||
fn each(&self, blk: fn(+K,+V) -> bool) {
|
||||
self.each_ref(|k,v| blk(copy *k, copy *v));
|
||||
}
|
||||
}
|
||||
impl<K: Hash IterBytes Eq copy, V> LinearMap<K,V> {
|
||||
impl<K: Hash IterBytes Eq Copy, V> LinearMap<K,V> {
|
||||
fn each_key(&self, blk: fn(+K) -> bool) {
|
||||
self.each_key_ref(|k| blk(copy *k));
|
||||
}
|
||||
}
|
||||
impl<K: Hash IterBytes Eq, V: copy> LinearMap<K,V> {
|
||||
impl<K: Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
|
||||
fn each_value(&self, blk: fn(+V) -> bool) {
|
||||
self.each_value_ref(|v| blk(copy *v));
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ impl TaskBuilder {
|
||||
spawn_raw(x.opts, x.gen_body(f));
|
||||
}
|
||||
/// Runs a task, while transfering ownership of one argument to the child.
|
||||
fn spawn_with<A: send>(+arg: A, +f: fn~(+A)) {
|
||||
fn spawn_with<A: Send>(+arg: A, +f: fn~(+A)) {
|
||||
let arg = ~mut Some(arg);
|
||||
do self.spawn {
|
||||
f(option::swap_unwrap(arg))
|
||||
@@ -398,7 +398,7 @@ impl TaskBuilder {
|
||||
* otherwise be required to establish communication from the parent
|
||||
* to the child.
|
||||
*/
|
||||
fn spawn_listener<A: send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
fn spawn_listener<A: Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
let setup_po = comm::Port();
|
||||
let setup_ch = comm::Chan(setup_po);
|
||||
do self.spawn {
|
||||
@@ -413,7 +413,7 @@ impl TaskBuilder {
|
||||
/**
|
||||
* Runs a new task, setting up communication in both directions
|
||||
*/
|
||||
fn spawn_conversation<A: send, B: send>
|
||||
fn spawn_conversation<A: Send, B: Send>
|
||||
(+f: fn~(comm::Port<A>, comm::Chan<B>))
|
||||
-> (comm::Port<B>, comm::Chan<A>) {
|
||||
let from_child = comm::Port();
|
||||
@@ -437,7 +437,7 @@ impl TaskBuilder {
|
||||
* # Failure
|
||||
* Fails if a future_result was already set for this task.
|
||||
*/
|
||||
fn try<T: send>(+f: fn~() -> T) -> Result<T,()> {
|
||||
fn try<T: Send>(+f: fn~() -> T) -> Result<T,()> {
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
let mut result = None;
|
||||
@@ -504,7 +504,7 @@ fn spawn_supervised(+f: fn~()) {
|
||||
task().supervised().spawn(f)
|
||||
}
|
||||
|
||||
fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
|
||||
fn spawn_with<A:Send>(+arg: A, +f: fn~(+A)) {
|
||||
/*!
|
||||
* Runs a task, while transfering ownership of one argument to the
|
||||
* child.
|
||||
@@ -518,7 +518,7 @@ fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
|
||||
task().spawn_with(arg, f)
|
||||
}
|
||||
|
||||
fn spawn_listener<A:send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
fn spawn_listener<A:Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
/*!
|
||||
* Runs a new task while providing a channel from the parent to the child
|
||||
*
|
||||
@@ -528,7 +528,7 @@ fn spawn_listener<A:send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
task().spawn_listener(f)
|
||||
}
|
||||
|
||||
fn spawn_conversation<A: send, B: send>
|
||||
fn spawn_conversation<A: Send, B: Send>
|
||||
(+f: fn~(comm::Port<A>, comm::Chan<B>))
|
||||
-> (comm::Port<B>, comm::Chan<A>) {
|
||||
/*!
|
||||
@@ -557,7 +557,7 @@ fn spawn_sched(mode: SchedMode, +f: fn~()) {
|
||||
task().sched_mode(mode).spawn(f)
|
||||
}
|
||||
|
||||
fn try<T:send>(+f: fn~() -> T) -> Result<T,()> {
|
||||
fn try<T:Send>(+f: fn~() -> T) -> Result<T,()> {
|
||||
/*!
|
||||
* Execute a function in another task and return either the return value
|
||||
* of the function or result::err.
|
||||
@@ -1314,10 +1314,10 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
||||
*
|
||||
* These two cases aside, the interface is safe.
|
||||
*/
|
||||
type LocalDataKey<T: owned> = &fn(+@T);
|
||||
type LocalDataKey<T: Owned> = &fn(+@T);
|
||||
|
||||
trait LocalData { }
|
||||
impl<T: owned> @T: LocalData { }
|
||||
impl<T: Owned> @T: LocalData { }
|
||||
|
||||
impl LocalData: Eq {
|
||||
pure fn eq(&&other: LocalData) -> bool unsafe {
|
||||
@@ -1365,7 +1365,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn key_to_key_value<T: owned>(
|
||||
unsafe fn key_to_key_value<T: Owned>(
|
||||
key: LocalDataKey<T>) -> *libc::c_void {
|
||||
|
||||
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
||||
@@ -1375,7 +1375,7 @@ unsafe fn key_to_key_value<T: owned>(
|
||||
}
|
||||
|
||||
// If returning Some(..), returns with @T with the map's reference. Careful!
|
||||
unsafe fn local_data_lookup<T: owned>(
|
||||
unsafe fn local_data_lookup<T: Owned>(
|
||||
map: TaskLocalMap, key: LocalDataKey<T>)
|
||||
-> Option<(uint, *libc::c_void)> {
|
||||
|
||||
@@ -1393,7 +1393,7 @@ unsafe fn local_data_lookup<T: owned>(
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn local_get_helper<T: owned>(
|
||||
unsafe fn local_get_helper<T: Owned>(
|
||||
task: *rust_task, key: LocalDataKey<T>,
|
||||
do_pop: bool) -> Option<@T> {
|
||||
|
||||
@@ -1414,21 +1414,21 @@ unsafe fn local_get_helper<T: owned>(
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn local_pop<T: owned>(
|
||||
unsafe fn local_pop<T: Owned>(
|
||||
task: *rust_task,
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get_helper(task, key, true)
|
||||
}
|
||||
|
||||
unsafe fn local_get<T: owned>(
|
||||
unsafe fn local_get<T: Owned>(
|
||||
task: *rust_task,
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get_helper(task, key, false)
|
||||
}
|
||||
|
||||
unsafe fn local_set<T: owned>(
|
||||
unsafe fn local_set<T: Owned>(
|
||||
task: *rust_task, key: LocalDataKey<T>, +data: @T) {
|
||||
|
||||
let map = get_task_local_map(task);
|
||||
@@ -1460,7 +1460,7 @@ unsafe fn local_set<T: owned>(
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn local_modify<T: owned>(
|
||||
unsafe fn local_modify<T: Owned>(
|
||||
task: *rust_task, key: LocalDataKey<T>,
|
||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||
|
||||
@@ -1476,7 +1476,7 @@ unsafe fn local_modify<T: owned>(
|
||||
* Remove a task-local data value from the table, returning the
|
||||
* reference that was originally created to insert it.
|
||||
*/
|
||||
unsafe fn local_data_pop<T: owned>(
|
||||
unsafe fn local_data_pop<T: Owned>(
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_pop(rustrt::rust_get_task(), key)
|
||||
@@ -1485,7 +1485,7 @@ unsafe fn local_data_pop<T: owned>(
|
||||
* Retrieve a task-local data value. It will also be kept alive in the
|
||||
* table until explicitly removed.
|
||||
*/
|
||||
unsafe fn local_data_get<T: owned>(
|
||||
unsafe fn local_data_get<T: Owned>(
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get(rustrt::rust_get_task(), key)
|
||||
@@ -1494,7 +1494,7 @@ unsafe fn local_data_get<T: owned>(
|
||||
* Store a value in task-local data. If this key already has a value,
|
||||
* that value is overwritten (and its destructor is run).
|
||||
*/
|
||||
unsafe fn local_data_set<T: owned>(
|
||||
unsafe fn local_data_set<T: Owned>(
|
||||
key: LocalDataKey<T>, +data: @T) {
|
||||
|
||||
local_set(rustrt::rust_get_task(), key, data)
|
||||
@@ -1503,7 +1503,7 @@ unsafe fn local_data_set<T: owned>(
|
||||
* Modify a task-local data value. If the function returns 'none', the
|
||||
* data is removed (and its reference dropped).
|
||||
*/
|
||||
unsafe fn local_data_modify<T: owned>(
|
||||
unsafe fn local_data_modify<T: Owned>(
|
||||
key: LocalDataKey<T>,
|
||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ impl &str: ToStr {
|
||||
fn to_str() -> ~str { str::from_slice(self) }
|
||||
}
|
||||
|
||||
impl<A: ToStr copy, B: ToStr copy> (A, B): ToStr {
|
||||
impl<A: ToStr Copy, B: ToStr Copy> (A, B): ToStr {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b) = self;
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
|
||||
}
|
||||
}
|
||||
impl<A: ToStr copy, B: ToStr copy, C: ToStr copy> (A, B, C): ToStr {
|
||||
impl<A: ToStr Copy, B: ToStr Copy, C: ToStr Copy> (A, B, C): ToStr {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b, c) = self;
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
|
||||
|
||||
@@ -12,7 +12,7 @@ trait TupleOps<T,U> {
|
||||
pure fn swap() -> (U, T);
|
||||
}
|
||||
|
||||
impl<T: copy, U: copy> (T, U): TupleOps<T,U> {
|
||||
impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> {
|
||||
|
||||
/// Return the first element of self
|
||||
pure fn first() -> T {
|
||||
@@ -39,7 +39,7 @@ trait ExtendedTupleOps<A,B> {
|
||||
fn map<C>(f: fn(A, B) -> C) -> ~[C];
|
||||
}
|
||||
|
||||
impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
|
||||
impl<A: Copy, B: Copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
|
||||
|
||||
fn zip() -> ~[(A, B)] {
|
||||
let (a, b) = self;
|
||||
@@ -52,7 +52,7 @@ impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
|
||||
impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
|
||||
|
||||
fn zip() -> ~[(A, B)] {
|
||||
// XXX: Bad copy
|
||||
|
||||
@@ -137,7 +137,7 @@ fn ArcDestruct<T>(data: *libc::c_void) -> ArcDestruct<T> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
||||
unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
|
||||
-> T {
|
||||
struct DeathThroes<T> {
|
||||
mut ptr: Option<~ArcData<T>>,
|
||||
@@ -207,9 +207,9 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
||||
* Data races between tasks can result in crashes and, with sufficient
|
||||
* cleverness, arbitrary type coercion.
|
||||
*/
|
||||
type SharedMutableState<T: send> = ArcDestruct<T>;
|
||||
type SharedMutableState<T: Send> = ArcDestruct<T>;
|
||||
|
||||
unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
||||
unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> {
|
||||
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||
unsafe {
|
||||
let ptr = unsafe::transmute(data);
|
||||
@@ -218,7 +218,7 @@ unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
unsafe fn get_shared_mutable_state<T: Send>(rc: &a/SharedMutableState<T>)
|
||||
-> &a/mut T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
@@ -230,7 +230,7 @@ unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
unsafe fn get_shared_immutable_state<T: Send>(rc: &a/SharedMutableState<T>)
|
||||
-> &a/T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
@@ -242,7 +242,7 @@ unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
|
||||
unsafe fn clone_shared_mutable_state<T: Send>(rc: &SharedMutableState<T>)
|
||||
-> SharedMutableState<T> {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
@@ -312,20 +312,20 @@ impl LittleLock {
|
||||
}
|
||||
}
|
||||
|
||||
struct ExData<T: send> { lock: LittleLock, mut failed: bool, mut data: T, }
|
||||
struct ExData<T: Send> { lock: LittleLock, mut failed: bool, mut data: T, }
|
||||
/**
|
||||
* An arc over mutable data that is protected by a lock. For library use only.
|
||||
*/
|
||||
struct Exclusive<T: send> { x: SharedMutableState<ExData<T>> }
|
||||
struct Exclusive<T: Send> { x: SharedMutableState<ExData<T>> }
|
||||
|
||||
fn exclusive<T:send >(+user_data: T) -> Exclusive<T> {
|
||||
fn exclusive<T:Send >(+user_data: T) -> Exclusive<T> {
|
||||
let data = ExData {
|
||||
lock: LittleLock(), mut failed: false, mut data: user_data
|
||||
};
|
||||
Exclusive { x: unsafe { shared_mutable_state(data) } }
|
||||
}
|
||||
|
||||
impl<T: send> Exclusive<T> {
|
||||
impl<T: Send> Exclusive<T> {
|
||||
// Duplicate an exclusive ARC, as std::arc::clone.
|
||||
fn clone() -> Exclusive<T> {
|
||||
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
||||
@@ -353,7 +353,7 @@ impl<T: send> Exclusive<T> {
|
||||
}
|
||||
|
||||
// FIXME(#2585) make this a by-move method on the exclusive
|
||||
fn unwrap_exclusive<T: send>(+arc: Exclusive<T>) -> T {
|
||||
fn unwrap_exclusive<T: Send>(+arc: Exclusive<T>) -> T {
|
||||
let Exclusive { x: x } = arc;
|
||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||
let ExData { data: data, _ } = inner;
|
||||
|
||||
@@ -17,7 +17,7 @@ pure fn ignore<T>(+_x: T) { }
|
||||
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
||||
/// original value of `*ptr`.
|
||||
#[inline(always)]
|
||||
fn with<T: copy, R>(
|
||||
fn with<T: Copy, R>(
|
||||
ptr: &mut T,
|
||||
+new_value: T,
|
||||
op: &fn() -> R) -> R
|
||||
|
||||
@@ -199,7 +199,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
|
||||
pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T] {
|
||||
let mut v = ~[];
|
||||
unchecked{reserve(v, n_elts)}
|
||||
let mut i: uint = 0u;
|
||||
@@ -211,7 +211,7 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
|
||||
}
|
||||
|
||||
/// Creates a new unique vector with the same contents as the slice
|
||||
pure fn from_slice<T: copy>(t: &[T]) -> ~[T] {
|
||||
pure fn from_slice<T: Copy>(t: &[T]) -> ~[T] {
|
||||
from_fn(t.len(), |i| t[i])
|
||||
}
|
||||
|
||||
@@ -281,10 +281,10 @@ pure fn from_mut<T>(+v: ~[mut T]) -> ~[T] {
|
||||
// Accessors
|
||||
|
||||
/// Returns the first element of a vector
|
||||
pure fn head<T: copy>(v: &[const T]) -> T { v[0] }
|
||||
pure fn head<T: Copy>(v: &[const T]) -> T { v[0] }
|
||||
|
||||
/// Returns a vector containing all but the first element of a slice
|
||||
pure fn tail<T: copy>(v: &[const T]) -> ~[T] {
|
||||
pure fn tail<T: Copy>(v: &[const T]) -> ~[T] {
|
||||
return slice(v, 1u, len(v));
|
||||
}
|
||||
|
||||
@@ -292,18 +292,18 @@ pure fn tail<T: copy>(v: &[const T]) -> ~[T] {
|
||||
* Returns a vector containing all but the first `n` \
|
||||
* elements of a slice
|
||||
*/
|
||||
pure fn tailn<T: copy>(v: &[const T], n: uint) -> ~[T] {
|
||||
pure fn tailn<T: Copy>(v: &[const T], n: uint) -> ~[T] {
|
||||
slice(v, n, len(v))
|
||||
}
|
||||
|
||||
/// Returns a vector containing all but the last element of a slice
|
||||
pure fn init<T: copy>(v: &[const T]) -> ~[T] {
|
||||
pure fn init<T: Copy>(v: &[const T]) -> ~[T] {
|
||||
assert len(v) != 0u;
|
||||
slice(v, 0u, len(v) - 1u)
|
||||
}
|
||||
|
||||
/// Returns the last element of the slice `v`, failing if the slice is empty.
|
||||
pure fn last<T: copy>(v: &[const T]) -> T {
|
||||
pure fn last<T: Copy>(v: &[const T]) -> T {
|
||||
if len(v) == 0u { fail ~"last_unsafe: empty vector" }
|
||||
v[len(v) - 1u]
|
||||
}
|
||||
@@ -312,13 +312,13 @@ pure fn last<T: copy>(v: &[const T]) -> T {
|
||||
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
||||
* or `none` if the vector is empty.
|
||||
*/
|
||||
pure fn last_opt<T: copy>(v: &[const T]) -> Option<T> {
|
||||
pure fn last_opt<T: Copy>(v: &[const T]) -> Option<T> {
|
||||
if len(v) == 0u { return None; }
|
||||
Some(v[len(v) - 1u])
|
||||
}
|
||||
|
||||
/// Returns a copy of the elements from [`start`..`end`) from `v`.
|
||||
pure fn slice<T: copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
|
||||
pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let mut result = ~[];
|
||||
@@ -365,7 +365,7 @@ pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
|
||||
}
|
||||
|
||||
/// Split the vector `v` by applying each element against the predicate `f`.
|
||||
fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
fn split<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
let ln = len(v);
|
||||
if (ln == 0u) { return ~[] }
|
||||
|
||||
@@ -388,7 +388,7 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
* Split the vector `v` by applying each element against the predicate `f` up
|
||||
* to `n` times.
|
||||
*/
|
||||
fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
||||
fn splitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
||||
let ln = len(v);
|
||||
if (ln == 0u) { return ~[] }
|
||||
|
||||
@@ -414,7 +414,7 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
||||
* Reverse split the vector `v` by applying each element against the predicate
|
||||
* `f`.
|
||||
*/
|
||||
fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
fn rsplit<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
let ln = len(v);
|
||||
if (ln == 0u) { return ~[] }
|
||||
|
||||
@@ -438,7 +438,7 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
||||
* Reverse split the vector `v` by applying each element against the predicate
|
||||
* `f` up to `n times.
|
||||
*/
|
||||
fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
||||
fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
||||
let ln = len(v);
|
||||
if (ln == 0u) { return ~[] }
|
||||
|
||||
@@ -589,7 +589,7 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
|
||||
fn push_all<T: Copy>(&v: ~[const T], rhs: &[const T]) {
|
||||
reserve(v, v.len() + rhs.len());
|
||||
|
||||
for uint::range(0u, rhs.len()) |i| {
|
||||
@@ -627,7 +627,7 @@ fn truncate<T>(&v: ~[const T], newlen: uint) {
|
||||
|
||||
// Appending
|
||||
#[inline(always)]
|
||||
pure fn append<T: copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
||||
pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
||||
let mut v <- lhs;
|
||||
unchecked {
|
||||
push_all(v, rhs);
|
||||
@@ -643,7 +643,7 @@ pure fn append_one<T>(+lhs: ~[T], +x: T) -> ~[T] {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn append_mut<T: copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
|
||||
pure fn append_mut<T: Copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
|
||||
let mut v = ~[mut];
|
||||
let mut i = 0u;
|
||||
while i < lhs.len() {
|
||||
@@ -671,7 +671,7 @@ pure fn append_mut<T: copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
|
||||
* * n - The number of elements to add
|
||||
* * initval - The value for the new elements
|
||||
*/
|
||||
fn grow<T: copy>(&v: ~[const T], n: uint, initval: T) {
|
||||
fn grow<T: Copy>(&v: ~[const T], n: uint, initval: T) {
|
||||
reserve_at_least(v, len(v) + n);
|
||||
let mut i: uint = 0u;
|
||||
|
||||
@@ -705,7 +705,7 @@ fn grow_fn<T>(&v: ~[const T], n: uint, op: iter::InitOp<T>) {
|
||||
* of the vector, expands the vector by replicating `initval` to fill the
|
||||
* intervening space.
|
||||
*/
|
||||
fn grow_set<T: copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
|
||||
fn grow_set<T: Copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
|
||||
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
|
||||
v[index] = val;
|
||||
}
|
||||
@@ -747,7 +747,7 @@ pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
|
||||
}
|
||||
|
||||
/// Apply a function to each pair of elements and return the results
|
||||
pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
|
||||
pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U],
|
||||
f: fn(T, U) -> V) -> ~[V] {
|
||||
let v0_len = len(v0);
|
||||
if v0_len != len(v1) { fail; }
|
||||
@@ -766,7 +766,7 @@ pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
|
||||
* If function `f` returns `none` then that element is excluded from
|
||||
* the resulting vector.
|
||||
*/
|
||||
pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> Option<U>)
|
||||
pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
|
||||
-> ~[U] {
|
||||
let mut result = ~[];
|
||||
for each(v) |elem| {
|
||||
@@ -785,7 +785,7 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> Option<U>)
|
||||
* Apply function `f` to each element of `v` and return a vector containing
|
||||
* only those elements for which `f` returned true.
|
||||
*/
|
||||
pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
|
||||
pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
|
||||
let mut result = ~[];
|
||||
for each(v) |elem| {
|
||||
if f(elem) { unsafe { push(result, elem); } }
|
||||
@@ -798,14 +798,14 @@ pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
|
||||
*
|
||||
* Flattens a vector of vectors of T into a single vector of T.
|
||||
*/
|
||||
pure fn concat<T: copy>(v: &[~[T]]) -> ~[T] {
|
||||
pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] {
|
||||
let mut r = ~[];
|
||||
for each(v) |inner| { unsafe { push_all(r, inner); } }
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Concatenate a vector of vectors, placing a given separator between each
|
||||
pure fn connect<T: copy>(v: &[~[T]], sep: T) -> ~[T] {
|
||||
pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
|
||||
let mut r: ~[T] = ~[];
|
||||
let mut first = true;
|
||||
for each(v) |inner| {
|
||||
@@ -816,7 +816,7 @@ pure fn connect<T: copy>(v: &[~[T]], sep: T) -> ~[T] {
|
||||
}
|
||||
|
||||
/// Reduce a vector from left to right
|
||||
pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
|
||||
pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
|
||||
let mut accum = z;
|
||||
do iter(v) |elt| {
|
||||
accum = p(accum, elt);
|
||||
@@ -825,7 +825,7 @@ pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
|
||||
}
|
||||
|
||||
/// Reduce a vector from right to left
|
||||
pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
|
||||
pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
|
||||
let mut accum = z;
|
||||
do riter(v) |elt| {
|
||||
accum = p(elt, accum);
|
||||
@@ -914,7 +914,7 @@ pure fn count<T: Eq>(v: &[T], x: T) -> uint {
|
||||
* When function `f` returns true then an option containing the element
|
||||
* is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
find_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
@@ -925,7 +925,7 @@ pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
* [`start`, `end`). When function `f` returns true then an option containing
|
||||
* the element is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
|
||||
pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> Option<T> {
|
||||
option::map(position_between(v, start, end, f), |i| v[i])
|
||||
}
|
||||
@@ -937,7 +937,7 @@ pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
|
||||
* `f` returns true then an option containing the element is returned. If `f`
|
||||
* matches no elements then none is returned.
|
||||
*/
|
||||
pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
rfind_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
@@ -948,7 +948,7 @@ pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
* [`start`, `end`). When function `f` returns true then an option containing
|
||||
* the element is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn rfind_between<T: copy>(v: &[T], start: uint, end: uint,
|
||||
pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> Option<T> {
|
||||
option::map(rposition_between(v, start, end, f), |i| v[i])
|
||||
}
|
||||
@@ -1028,7 +1028,7 @@ pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
|
||||
/**
|
||||
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
||||
*/
|
||||
pure fn unzip_slice<T: copy, U: copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||
pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||
let mut as = ~[], bs = ~[];
|
||||
for each(v) |p| {
|
||||
let (a, b) = p;
|
||||
@@ -1063,7 +1063,7 @@ pure fn unzip<T,U>(+v: ~[(T, U)]) -> (~[T], ~[U]) {
|
||||
/**
|
||||
* Convert two vectors to a vector of pairs, by reference. As zip().
|
||||
*/
|
||||
pure fn zip_slice<T: copy, U: copy>(v: &[const T], u: &[const U])
|
||||
pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U])
|
||||
-> ~[(T, U)] {
|
||||
let mut zipped = ~[];
|
||||
let sz = len(v);
|
||||
@@ -1113,7 +1113,7 @@ fn reverse<T>(v: ~[mut T]) {
|
||||
|
||||
|
||||
/// Returns a vector with the order of elements reversed
|
||||
pure fn reversed<T: copy>(v: &[const T]) -> ~[T] {
|
||||
pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
|
||||
let mut rs: ~[T] = ~[];
|
||||
let mut i = len::<T>(v);
|
||||
if i == 0u { return rs; } else { i -= 1u; }
|
||||
@@ -1317,7 +1317,7 @@ pure fn riteri<T>(v: &[T], f: fn(uint, T)) {
|
||||
* The total number of permutations produced is `len(v)!`. If `v` contains
|
||||
* repeated elements, then some permutations are repeated.
|
||||
*/
|
||||
pure fn permute<T: copy>(v: &[const T], put: fn(~[T])) {
|
||||
pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) {
|
||||
let ln = len(v);
|
||||
if ln == 0u {
|
||||
put(~[]);
|
||||
@@ -1337,7 +1337,7 @@ pure fn permute<T: copy>(v: &[const T], put: fn(~[T])) {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
||||
pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
||||
let mut ww = ~[];
|
||||
assert 1u <= nn;
|
||||
vec::iteri (xx, |ii, _x| {
|
||||
@@ -1480,14 +1480,14 @@ impl<T: Ord> @[T]: Ord {
|
||||
}
|
||||
|
||||
#[cfg(notest)]
|
||||
impl<T: copy> ~[T]: Add<&[const T],~[T]> {
|
||||
impl<T: Copy> ~[T]: Add<&[const T],~[T]> {
|
||||
#[inline(always)]
|
||||
pure fn add(rhs: &[const T]) -> ~[T] {
|
||||
append(copy self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: copy> ~[mut T]: Add<&[const T],~[mut T]> {
|
||||
impl<T: Copy> ~[mut T]: Add<&[const T],~[mut T]> {
|
||||
#[inline(always)]
|
||||
pure fn add(rhs: &[const T]) -> ~[mut T] {
|
||||
append_mut(self, rhs)
|
||||
@@ -1522,7 +1522,7 @@ trait CopyableVector<T> {
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
impl<T: copy> &[const T]: CopyableVector<T> {
|
||||
impl<T: Copy> &[const T]: CopyableVector<T> {
|
||||
/// Returns the first element of a vector
|
||||
#[inline]
|
||||
pure fn head() -> T { head(self) }
|
||||
@@ -1541,7 +1541,7 @@ impl<T: copy> &[const T]: CopyableVector<T> {
|
||||
}
|
||||
|
||||
trait ImmutableVector<T> {
|
||||
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U;
|
||||
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
|
||||
pure fn iter(f: fn(T));
|
||||
pure fn iteri(f: fn(uint, T));
|
||||
pure fn riter(f: fn(T));
|
||||
@@ -1551,7 +1551,7 @@ trait ImmutableVector<T> {
|
||||
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
|
||||
pure fn alli(f: fn(uint, T) -> bool) -> bool;
|
||||
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U];
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U];
|
||||
pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U];
|
||||
}
|
||||
|
||||
trait ImmutableEqVector<T: Eq> {
|
||||
@@ -1565,7 +1565,7 @@ trait ImmutableEqVector<T: Eq> {
|
||||
impl<T> &[T]: ImmutableVector<T> {
|
||||
/// Reduce a vector from right to left
|
||||
#[inline]
|
||||
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
|
||||
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
|
||||
/**
|
||||
* Iterates over a vector
|
||||
*
|
||||
@@ -1641,7 +1641,7 @@ impl<T> &[T]: ImmutableVector<T> {
|
||||
* the resulting vector.
|
||||
*/
|
||||
#[inline]
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U] {
|
||||
pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U] {
|
||||
filter_map(self, f)
|
||||
}
|
||||
}
|
||||
@@ -1679,7 +1679,7 @@ trait ImmutableCopyableVector<T> {
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
impl<T: copy> &[T]: ImmutableCopyableVector<T> {
|
||||
impl<T: Copy> &[T]: ImmutableCopyableVector<T> {
|
||||
/**
|
||||
* Construct a new vector from the elements of a vector for which some
|
||||
* predicate holds.
|
||||
@@ -1785,7 +1785,7 @@ mod unsafe {
|
||||
* Unchecked vector indexing.
|
||||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn get<T: copy>(v: &[const T], i: uint) -> T {
|
||||
unsafe fn get<T: Copy>(v: &[const T], i: uint) -> T {
|
||||
as_buf(v, |p, _len| *ptr::offset(p, i))
|
||||
}
|
||||
|
||||
@@ -1938,7 +1938,7 @@ impl<A: Eq> &[A]: iter::EqIter<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: copy> &[A]: iter::CopyableIter<A> {
|
||||
impl<A: Copy> &[A]: iter::CopyableIter<A> {
|
||||
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
}
|
||||
@@ -1955,7 +1955,7 @@ impl<A: copy> &[A]: iter::CopyableIter<A> {
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
||||
}
|
||||
|
||||
impl<A: copy Ord> &[A]: iter::CopyableOrderedIter<A> {
|
||||
impl<A: Copy Ord> &[A]: iter::CopyableOrderedIter<A> {
|
||||
pure fn min() -> A { iter::min(self) }
|
||||
pure fn max() -> A { iter::max(self) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user