Some examples of call expressions:
```
-# use std::str::from_str;
# fn add(x: int, y: int) -> int { 0 }
let x: int = add(1, 2);
}
}
-#[cfg(not(stage0))]
-impl Box<Any> {
- pub fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
- if self.is::<T>() {
- unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject =
- mem::transmute::<Box<Any>, TraitObject>(self);
-
- // Extract the data pointer
- Ok(mem::transmute(to.data))
- }
- } else {
- Err(self)
- }
- }
-}
-
/// Extension methods for an owning `Any` trait object.
#[unstable = "post-DST and coherence changes, this will not be a trait but \
rather a direct `impl` on `Box<Any>`"]
-#[cfg(stage0)]
pub trait BoxAny {
/// Returns the boxed value if it is of type `T`, or
/// `Err(Self)` if it isn't.
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
}
-#[stable]
-#[cfg(stage0)]
impl BoxAny for Box<Any> {
#[inline]
+ #[unstable = "method may be renamed with respect to other downcasting \
+ methods"]
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
if self.is::<T>() {
unsafe {
use core::iter::{mod, FromIterator};
use core::num::Int;
use core::ops::Index;
-use core::slice::{Iter, IterMut};
+use core::slice;
use core::{u8, u32, uint};
use bitv_set; //so meta
/// `None` on error.
///
/// ```
- /// use std::str::from_str;
- ///
/// let good_year_from_input = "1909";
/// let bad_year_from_input = "190blarg";
/// let good_year = good_year_from_input.parse().unwrap_or_default();
///
/// ```
/// use std::io::IoResult;
- /// use std::str::from_str;
///
/// let mut buffer = &mut b"1\n2\n3\n4\n";
///
use syntax::diagnostic::{Emitter, Handler, Level, mk_handler};
use std::c_str::{ToCStr, CString};
-use std::comm::channel;
use std::io::Command;
use std::io::fs;
use std::iter::Unfold;
}
fn escape_char(writer: &mut fmt::Writer, v: char) -> fmt::Result {
- let mut buf = [0, .. 4];
+ let mut buf = [0; 4];
let n = v.encode_utf8(&mut buf).unwrap();
let buf = unsafe { str::from_utf8_unchecked(buf[0..n]) };
escape_str(writer, buf)
#[cfg(test)]
mod tests {
use self::BadReaderBehavior::*;
- use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput};
+ use super::{IoResult, MemReader, NoProgress, InvalidInput};
use prelude::v1::*;
use uint;
#[cfg(test)]
mod test {
- use prelude::v1::*;
-
use super::Timer;
use thread::Thread;
use time::Duration;
#[cfg(test)]
mod tests {
- use prelude::v1::Option::{mod, Some, None};
- use prelude::v1::{Vec, Clone, AsSlice, SliceExt, CloneSliceExt, IteratorExt};
- use prelude::v1::{DoubleEndedIteratorExt, Str, ToString, GenericPath};
-
use super::PathPrefix::*;
use super::parse_prefix;
use super::*;
static C: StaticCondvar = CONDVAR_INIT;
static M: StaticMutex = MUTEX_INIT;
- let mut g = M.lock().unwrap();
+ let g = M.lock().unwrap();
let _t = Thread::spawn(move|| {
let _g = M.lock().unwrap();
C.notify_one();
g = C.wait(g).unwrap();
drop(g);
- C.wait(M2.lock().unwrap()).unwrap();
+ let _ = C.wait(M2.lock().unwrap()).unwrap();
}
}
use prelude::v1::*;
use thread::Thread;
- use super::*;
use sync::mpsc::*;
// Don't use the libstd version so we can pull in the right Select structure
fn test_mutex_arc_poison() {
let arc = Arc::new(Mutex::new(1i));
let arc2 = arc.clone();
- Thread::spawn(move|| {
+ let _ = Thread::spawn(move|| {
let lock = arc2.lock().unwrap();
assert_eq!(*lock, 2);
}).join();
use prelude::v1::*;
use cell::UnsafeCell;
-use comm::{channel, Sender, Receiver};
use mem;
use rt;
use sync::{StaticMutex, StaticCondvar};
use prelude::v1::*;
-use prelude::*;
-
use libc;
use c_str::CString;
use mem;
use mem;
use io::{mod, IoResult, IoError};
use sync::{Once, ONCE_INIT};
-use comm::Sender;
macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
lock: ::sync::MUTEX_INIT,
cond: ::sync::CONDVAR_INIT,
- chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
+ chan: ::cell::UnsafeCell { value: 0 as *mut ::sync::mpsc::Sender<$m> },
signal: ::cell::UnsafeCell { value: 0 },
initialized: ::cell::UnsafeCell { value: false },
shutdown: ::cell::UnsafeCell { value: false },
use libc;
use ptr;
-use comm;
-use comm::{channel, Sender, Receiver};
use io::IoResult;
+use sync::mpsc::{channel, Sender, Receiver, TryRecvError};
use sys::c;
use sys::fs::FileDesc;
use sys_common::helper_thread::Helper;
chans.push((c, one));
}
Ok(RemoveTimer(obj, c)) => {
- c.send(());
+ c.send(()).unwrap();
match objs.iter().position(|&o| o == obj) {
Some(i) => {
drop(objs.remove(i));
None => {}
}
}
- Err(comm::Disconnected) => {
+ Err(TryRecvError::Disconnected) => {
assert_eq!(objs.len(), 1);
assert_eq!(chans.len(), 0);
break 'outer;
let (tx, rx) = channel();
HELPER.send(RemoveTimer(self.obj, tx));
- rx.recv();
+ rx.recv().unwrap();
self.on_worker = false;
}
use prelude::v1::*;
use any::{Any, AnyRefExt};
- use boxed::BoxAny;
use sync::mpsc::{channel, Sender};
+ use boxed::BoxAny;
use result;
use std::io::{ChanReader, ChanWriter};
use super::{Thread, Builder};
// different scalability characteristics compared to the select
// version.
-use std::comm::{channel, Sender, Receiver};
-use std::comm;
+use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::str::from_str;
use std::thread::Thread;
let mut count = 0u;
let mut done = false;
while !done {
- match requests.recv_opt() {
- Ok(request::get_count) => { responses.send(count.clone()); }
+ match requests.recv() {
+ Ok(request::get_count) => { responses.send(count.clone()).unwrap(); }
Ok(request::bytes(b)) => {
//println!("server: received {} bytes", b);
count += b;
_ => { }
}
}
- responses.send(count);
+ responses.send(count).unwrap();
//println!("server exiting");
}
worker_results.push(Thread::spawn(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
- to_child.send(request::bytes(num_bytes));
+ to_child.send(request::bytes(num_bytes)).unwrap();
}
//println!("worker {} exiting", i);
}));
}
//println!("sending stop message");
- to_child.send(request::stop);
+ to_child.send(request::stop).unwrap();
move_out(to_child);
- result = Some(from_child.recv());
+ result = Some(from_child.recv().unwrap());
});
let result = result.unwrap();
print!("Count is {}\n", result);
//
// I *think* it's the same, more or less.
-use std::comm::{channel, Sender, Receiver};
+use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
-use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
use std::uint;
let mut count: uint = 0;
let mut done = false;
while !done {
- match requests.recv_opt() {
+ match requests.recv() {
Ok(request::get_count) => { responses.send(count.clone()); }
Ok(request::bytes(b)) => {
//println!("server: received {} bytes", b);
fn run(args: &[String]) {
let (to_parent, from_child) = channel();
- let size = from_str::<uint>(args[1].as_slice()).unwrap();
- let workers = from_str::<uint>(args[2].as_slice()).unwrap();
+ let size = args[1].parse::<uint>().unwrap();
+ let workers = args[2].parse::<uint>().unwrap();
let num_bytes = 100;
let mut result = None;
let mut to_parent = Some(to_parent);
//println!("sending stop message");
//to_child.send(stop);
//move_out(to_child);
- result = Some(from_child.recv());
+ result = Some(from_child.recv().unwrap());
});
let result = result.unwrap();
print!("Count is {}\n", result);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::comm::channel;
+use std::sync::mpsc::channel;
use std::os;
use std::str::from_str;
use std::thread::Thread;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::comm::channel;
+use std::sync::mpsc::channel;
use std::os;
-use std::str::from_str;
use std::thread::Thread;
use std::uint;
tx.send(parfib(n-1));
}).detach();
let m2 = parfib(n-2);
- return (rx.recv() + m2);
+ return (rx.recv().unwrap() + m2);
}
fn main() {
let args = os::args();
let args = args.as_slice();
let n = if args.len() == 2 {
- from_str::<uint>(args[1].as_slice()).unwrap()
+ args[1].parse::<uint>().unwrap()
} else {
10
};
} else if args.len() <= 1u {
8
} else {
- from_str(args[1].as_slice()).unwrap()
+ args[1].parse().unwrap()
};
let min_depth = 4;
let max_depth = if min_depth + 2 > n {min_depth + 2} else {n};
// no-pretty-expanded
use self::Color::{Red, Yellow, Blue};
-use std::comm::{channel, Sender, Receiver};
+use std::sync::mpsc::{channel, Sender, Receiver};
use std::fmt;
use std::str::from_str;
use std::thread::Thread;
loop {
// ask for a pairing
- to_rendezvous.send(CreatureInfo {name: name, color: color});
+ to_rendezvous.send(CreatureInfo {name: name, color: color}).unwrap();
// log and change, or quit
match rendezvous.next() {
}
// log creatures met and evil clones of self
let report = format!("{}{}", creatures_met, Number(evil_clones_met));
- to_rendezvous_log.send(report);
+ to_rendezvous_log.send(report).unwrap();
}
fn rendezvous(nn: uint, set: Vec<Color>) {
// set up meetings...
for _ in range(0, nn) {
- let fst_creature = from_creatures.recv();
- let snd_creature = from_creatures.recv();
+ let fst_creature = from_creatures.recv().unwrap();
+ let snd_creature = from_creatures.recv().unwrap();
creatures_met += 2;
- to_creature[fst_creature.name].send(snd_creature);
- to_creature[snd_creature.name].send(fst_creature);
+ to_creature[fst_creature.name].send(snd_creature).unwrap();
+ to_creature[snd_creature.name].send(fst_creature).unwrap();
}
// tell each creature to stop
fn main() {
let n = std::os::args().as_slice()
.get(1)
- .and_then(|arg| from_str(arg.as_slice()))
+ .and_then(|arg| arg.parse())
.unwrap_or(2i32);
let (checksum, maxflips) = fannkuch(n);
use std::ascii::{AsciiExt, OwnedAsciiExt};
use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::collections::HashMap;
-use std::comm::{channel, Sender, Receiver};
+use std::sync::mpsc::{channel, Sender, Receiver};
use std::mem::replace;
use std::num::Float;
use std::option;
loop {
- line = from_parent.recv();
+ line = from_parent.recv().unwrap();
if line == Vec::new() { break; }
carry.push_all(line.as_slice());
// now fetch and print result messages
for (ii, _sz) in sizes.iter().enumerate() {
- println!("{}", from_child[ii].recv());
+ println!("{}", from_child[ii].recv().unwrap());
}
}
// no-pretty-expanded FIXME #15189
-use std::comm::channel;
+use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread::Thread;
Thread::spawn(move|| {
let mut data = Data::new();
search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data);
- tx.send(data);
+ tx.send(data).unwrap();
}).detach();
}
// collecting the results
drop(tx);
- let mut data = rx.recv();
+ let mut data = rx.recv().unwrap();
for d in rx.iter() { data.reduce_from(d); }
data
}
extern crate getopts;
-use std::comm::{channel, Sender};
+use std::sync::mpsc::{channel, Sender};
use std::os;
use std::result::Result::{Ok, Err};
use std::str::from_str;
fn fib(n: int) -> int {
fn pfib(tx: &Sender<int>, n: int) {
if n == 0 {
- tx.send(0);
+ tx.send(0).unwrap();
} else if n <= 2 {
- tx.send(1);
+ tx.send(1).unwrap();
} else {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
Thread::spawn(move|| pfib(&tx2, n - 1)).detach();
let tx2 = tx1.clone();
Thread::spawn(move|| pfib(&tx2, n - 2)).detach();
- tx.send(rx.recv() + rx.recv());
+ tx.send(rx.recv().unwrap() + rx.recv().unwrap());
}
}
let (tx, rx) = channel();
Thread::spawn(move|| pfib(&tx, n) ).detach();
- rx.recv()
+ rx.recv().unwrap()
}
struct Config {
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
-use std::comm::{channel, Sender, Receiver};
+use std::sync::mpsc::{channel, Sender, Receiver};
use std::str::from_str;
use std::thread::Thread;
// ignore-pretty very bad with line comments
-use std::comm::{mod, channel};
+use std::sync::mpsc::{channel, Sender};
use std::os;
use std::str::from_str;
use std::task;
use std::thread::Thread;
use std::uint;
-fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
+fn child_generation(gens_left: uint, tx: Sender<()>) {
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
if gens_left > 0 {
child_generation(gens_left - 1, tx); // recurse
} else {
- tx.send(())
+ tx.send(()).unwrap()
}
}).detach();
}
let (tx, rx) = channel();
child_generation(from_str::<uint>(args[1].as_slice()).unwrap(), tx);
- if rx.recv_opt().is_err() {
+ if rx.recv().is_err() {
panic!("it happened when we slumbered");
}
}
trait To {
// This is a typo, the return type should be `<Dst as From<Self>>::Output`
fn to<Dst: From<Self>>(self) -> <Dst as From<Self>>::Dst {
- //~ error: the trait `core::kinds::Sized` is not implemented
+ //~^ error: the trait `core::kinds::Sized` is not implemented
From::from(self)
}
}