Skip to content

Commit

Permalink
Convert all kind bounds to camel case. Remove send, owned keywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Sep 8, 2012
1 parent 07fe561 commit 3bd1f32
Show file tree
Hide file tree
Showing 167 changed files with 613 additions and 622 deletions.
10 changes: 5 additions & 5 deletions doc/rust.md
Expand Up @@ -449,7 +449,7 @@ Two examples of paths with type arguments:
~~~~
# use std::map;
# fn f() {
# fn id<T:copy>(t: T) -> T { t }
# fn id<T:Copy>(t: T) -> T { t }
type t = map::hashmap<int,~str>; // Type arguments used in a type expression
let x = id::<int>(10); // Type arguments used in a call expression
# }
Expand Down Expand Up @@ -1056,7 +1056,7 @@ An example of a pure function that uses an unchecked block:
~~~~
# use std::list::*;
fn pure_foldl<T, U: copy>(ls: List<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
fn pure_foldl<T, U: Copy>(ls: List<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
match ls {
Nil => u,
Cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
Expand Down Expand Up @@ -1110,7 +1110,7 @@ type can always be moved, but they can only be copied when the
parameter is given a [`copy` bound](#type-kinds).

~~~~
fn id<T: copy>(x: T) -> T { x }
fn id<T: Copy>(x: T) -> T { x }
~~~~

Similarly, [trait](#traits) bounds can be specified for type
Expand Down Expand Up @@ -2638,7 +2638,7 @@ Every struct item defines a type.
Within the body of an item that has type parameter declarations, the names of its type parameters are types:

~~~~~~~
fn map<A: copy, B: copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
if xs.len() == 0 { return ~[]; }
let first: B = f(xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
Expand Down Expand Up @@ -2706,7 +2706,7 @@ Putting `x` into a shared box involves copying, and the `T` parameter
is assumed to be noncopyable. To change that, a bound is declared:

~~~~
fn box<T: copy>(x: T) -> @T { @x }
fn box<T: Copy>(x: T) -> @T { @x }
~~~~

Calling this second version of `box` on a noncopyable type is not
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorial.md
Expand Up @@ -1583,20 +1583,20 @@ unless you explicitly declare that type parameter to have copyable
// This does not compile
fn head_bad<T>(v: ~[T]) -> T { v[0] }
// This does
fn head<T: copy>(v: ~[T]) -> T { v[0] }
fn head<T: Copy>(v: ~[T]) -> T { v[0] }
~~~~

When instantiating a generic function, you can only instantiate it
with types that fit its kinds. So you could not apply `head` to a
resource type. Rust has several kinds that can be used as type bounds:

* `copy` - Copyable types. All types are copyable unless they
* `Copy` - Copyable types. All types are copyable unless they
are classes with destructors or otherwise contain
classes with destructors.
* `send` - Sendable types. All types are sendable unless they
* `Send` - Sendable types. All types are sendable unless they
contain shared boxes, closures, or other local-heap-allocated
types.
* `const` - Constant types. These are types that do not contain
* `Const` - Constant types. These are types that do not contain
mutable fields nor shared boxes.

> ***Note:*** Rust type kinds are syntactically very similar to
Expand Down Expand Up @@ -2002,7 +2002,7 @@ and one for values. This means that this code is valid:
~~~~
mod buffalo {
type buffalo = int;
fn buffalo<buffalo: copy>(buffalo: buffalo) -> buffalo { buffalo }
fn buffalo<buffalo>(+buffalo: buffalo) -> buffalo { buffalo }
}
fn main() {
let buffalo: buffalo::buffalo = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzer/fuzzer.rs
Expand Up @@ -239,7 +239,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
pprust::ty_to_str, replace_ty_in_crate, cx);
}

fn check_variants_T<T: copy>(
fn check_variants_T<T: Copy>(
crate: ast::crate,
codemap: codemap::codemap,
filename: &Path,
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/at_vec.rs
Expand Up @@ -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]); }
Expand Down Expand Up @@ -125,15 +125,15 @@ 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; }
}
}

#[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)
Expand Down
34 changes: 17 additions & 17 deletions src/libcore/comm.rs
Expand Up @@ -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>)
}

Expand All @@ -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) }
Expand All @@ -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) }
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -167,15 +167,15 @@ 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))
}

/**
* 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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/dlist.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/dvec.rs
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/either.rs
Expand Up @@ -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] = ~[];
Expand All @@ -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] = ~[];
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
*
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/future.rs
Expand Up @@ -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

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
Expand All @@ -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) -> !
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/iter-trait.rs
Expand Up @@ -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)
}
Expand All @@ -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) }
}
Expand Down

0 comments on commit 3bd1f32

Please sign in to comment.