Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass rename if_ok! to try! #12401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ use serialize::Encodable;
use serialize;
use collections::TreeMap;

macro_rules! if_ok( ($e:expr) => (
macro_rules! try( ($e:expr) => (
match $e { Ok(e) => e, Err(e) => { self.error = Err(e); return } }
) )

Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a> Encoder<'a> {
}

impl<'a> serialize::Encoder for Encoder<'a> {
fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")) }
fn emit_nil(&mut self) { try!(write!(self.wr, "null")) }

fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
Expand All @@ -358,20 +358,20 @@ impl<'a> serialize::Encoder for Encoder<'a> {

fn emit_bool(&mut self, v: bool) {
if v {
if_ok!(write!(self.wr, "true"));
try!(write!(self.wr, "true"));
} else {
if_ok!(write!(self.wr, "false"));
try!(write!(self.wr, "false"));
}
}

fn emit_f64(&mut self, v: f64) {
if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)))
try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)))
}
fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }

fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
fn emit_str(&mut self, v: &str) {
if_ok!(write!(self.wr, "{}", escape_str(v)))
try!(write!(self.wr, "{}", escape_str(v)))
}

fn emit_enum(&mut self, _name: &str, f: |&mut Encoder<'a>|) { f(self) }
Expand All @@ -385,19 +385,19 @@ impl<'a> serialize::Encoder for Encoder<'a> {
// Bunny => "Bunny"
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
if cnt == 0 {
if_ok!(write!(self.wr, "{}", escape_str(name)));
try!(write!(self.wr, "{}", escape_str(name)));
} else {
if_ok!(write!(self.wr, "\\{\"variant\":"));
if_ok!(write!(self.wr, "{}", escape_str(name)));
if_ok!(write!(self.wr, ",\"fields\":["));
try!(write!(self.wr, "\\{\"variant\":"));
try!(write!(self.wr, "{}", escape_str(name)));
try!(write!(self.wr, ",\"fields\":["));
f(self);
if_ok!(write!(self.wr, "]\\}"));
try!(write!(self.wr, "]\\}"));
}
}

fn emit_enum_variant_arg(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
if idx != 0 {
if_ok!(write!(self.wr, ","));
try!(write!(self.wr, ","));
}
f(self);
}
Expand All @@ -418,17 +418,17 @@ impl<'a> serialize::Encoder for Encoder<'a> {
}

fn emit_struct(&mut self, _: &str, _: uint, f: |&mut Encoder<'a>|) {
if_ok!(write!(self.wr, r"\{"));
try!(write!(self.wr, r"\{"));
f(self);
if_ok!(write!(self.wr, r"\}"));
try!(write!(self.wr, r"\}"));
}

fn emit_struct_field(&mut self,
name: &str,
idx: uint,
f: |&mut Encoder<'a>|) {
if idx != 0 { if_ok!(write!(self.wr, ",")) }
if_ok!(write!(self.wr, "{}:", escape_str(name)));
if idx != 0 { try!(write!(self.wr, ",")) }
try!(write!(self.wr, "{}:", escape_str(name)));
f(self);
}

Expand All @@ -454,31 +454,31 @@ impl<'a> serialize::Encoder for Encoder<'a> {
fn emit_option_some(&mut self, f: |&mut Encoder<'a>|) { f(self); }

fn emit_seq(&mut self, _len: uint, f: |&mut Encoder<'a>|) {
if_ok!(write!(self.wr, "["));
try!(write!(self.wr, "["));
f(self);
if_ok!(write!(self.wr, "]"));
try!(write!(self.wr, "]"));
}

fn emit_seq_elt(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
if idx != 0 {
if_ok!(write!(self.wr, ","));
try!(write!(self.wr, ","));
}
f(self)
}

fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>|) {
if_ok!(write!(self.wr, r"\{"));
try!(write!(self.wr, r"\{"));
f(self);
if_ok!(write!(self.wr, r"\}"));
try!(write!(self.wr, r"\}"));
}

fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
if idx != 0 { if_ok!(write!(self.wr, ",")) }
if idx != 0 { try!(write!(self.wr, ",")) }
f(self)
}

fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
if_ok!(write!(self.wr, ":"));
try!(write!(self.wr, ":"));
f(self)
}
}
Expand All @@ -503,7 +503,7 @@ impl<'a> PrettyEncoder<'a> {
}

impl<'a> serialize::Encoder for PrettyEncoder<'a> {
fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")); }
fn emit_nil(&mut self) { try!(write!(self.wr, "null")); }

fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
Expand All @@ -519,20 +519,20 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {

fn emit_bool(&mut self, v: bool) {
if v {
if_ok!(write!(self.wr, "true"));
try!(write!(self.wr, "true"));
} else {
if_ok!(write!(self.wr, "false"));
try!(write!(self.wr, "false"));
}
}

fn emit_f64(&mut self, v: f64) {
if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)));
try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)));
}
fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }

fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
fn emit_str(&mut self, v: &str) {
if_ok!(write!(self.wr, "{}", escape_str(v)));
try!(write!(self.wr, "{}", escape_str(v)));
}

fn emit_enum(&mut self, _name: &str, f: |&mut PrettyEncoder<'a>|) {
Expand All @@ -545,24 +545,24 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
cnt: uint,
f: |&mut PrettyEncoder<'a>|) {
if cnt == 0 {
if_ok!(write!(self.wr, "{}", escape_str(name)));
try!(write!(self.wr, "{}", escape_str(name)));
} else {
self.indent += 2;
if_ok!(write!(self.wr, "[\n{}{},\n", spaces(self.indent),
try!(write!(self.wr, "[\n{}{},\n", spaces(self.indent),
escape_str(name)));
f(self);
self.indent -= 2;
if_ok!(write!(self.wr, "\n{}]", spaces(self.indent)));
try!(write!(self.wr, "\n{}]", spaces(self.indent)));
}
}

fn emit_enum_variant_arg(&mut self,
idx: uint,
f: |&mut PrettyEncoder<'a>|) {
if idx != 0 {
if_ok!(write!(self.wr, ",\n"));
try!(write!(self.wr, ",\n"));
}
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
try!(write!(self.wr, "{}", spaces(self.indent)));
f(self)
}

Expand All @@ -587,13 +587,13 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
len: uint,
f: |&mut PrettyEncoder<'a>|) {
if len == 0 {
if_ok!(write!(self.wr, "\\{\\}"));
try!(write!(self.wr, "\\{\\}"));
} else {
if_ok!(write!(self.wr, "\\{"));
try!(write!(self.wr, "\\{"));
self.indent += 2;
f(self);
self.indent -= 2;
if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
try!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
}
}

Expand All @@ -602,11 +602,11 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
idx: uint,
f: |&mut PrettyEncoder<'a>|) {
if idx == 0 {
if_ok!(write!(self.wr, "\n"));
try!(write!(self.wr, "\n"));
} else {
if_ok!(write!(self.wr, ",\n"));
try!(write!(self.wr, ",\n"));
}
if_ok!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name)));
try!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name)));
f(self);
}

Expand Down Expand Up @@ -635,50 +635,50 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {

fn emit_seq(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) {
if len == 0 {
if_ok!(write!(self.wr, "[]"));
try!(write!(self.wr, "[]"));
} else {
if_ok!(write!(self.wr, "["));
try!(write!(self.wr, "["));
self.indent += 2;
f(self);
self.indent -= 2;
if_ok!(write!(self.wr, "\n{}]", spaces(self.indent)));
try!(write!(self.wr, "\n{}]", spaces(self.indent)));
}
}

fn emit_seq_elt(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) {
if idx == 0 {
if_ok!(write!(self.wr, "\n"));
try!(write!(self.wr, "\n"));
} else {
if_ok!(write!(self.wr, ",\n"));
try!(write!(self.wr, ",\n"));
}
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
try!(write!(self.wr, "{}", spaces(self.indent)));
f(self)
}

fn emit_map(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) {
if len == 0 {
if_ok!(write!(self.wr, "\\{\\}"));
try!(write!(self.wr, "\\{\\}"));
} else {
if_ok!(write!(self.wr, "\\{"));
try!(write!(self.wr, "\\{"));
self.indent += 2;
f(self);
self.indent -= 2;
if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
try!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
}
}

fn emit_map_elt_key(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) {
if idx == 0 {
if_ok!(write!(self.wr, "\n"));
try!(write!(self.wr, "\n"));
} else {
if_ok!(write!(self.wr, ",\n"));
try!(write!(self.wr, ",\n"));
}
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
try!(write!(self.wr, "{}", spaces(self.indent)));
f(self);
}

fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut PrettyEncoder<'a>|) {
if_ok!(write!(self.wr, ": "));
try!(write!(self.wr, ": "));
f(self);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,48 +376,48 @@ pub fn write_boxplot(w: &mut io::Writer, s: &Summary,
let range_width = width_hint - overhead_width;;
let char_step = range / (range_width as f64);

if_ok!(write!(w, "{} |", lostr));
try!(write!(w, "{} |", lostr));

let mut c = 0;
let mut v = lo;

while c < range_width && v < s.min {
if_ok!(write!(w, " "));
try!(write!(w, " "));
v += char_step;
c += 1;
}
if_ok!(write!(w, "["));
try!(write!(w, "["));
c += 1;
while c < range_width && v < q1 {
if_ok!(write!(w, "-"));
try!(write!(w, "-"));
v += char_step;
c += 1;
}
while c < range_width && v < q2 {
if_ok!(write!(w, "*"));
try!(write!(w, "*"));
v += char_step;
c += 1;
}
if_ok!(write!(w, r"\#"));
try!(write!(w, r"\#"));
c += 1;
while c < range_width && v < q3 {
if_ok!(write!(w, "*"));
try!(write!(w, "*"));
v += char_step;
c += 1;
}
while c < range_width && v < s.max {
if_ok!(write!(w, "-"));
try!(write!(w, "-"));
v += char_step;
c += 1;
}
if_ok!(write!(w, "]"));
try!(write!(w, "]"));
while c < range_width {
if_ok!(write!(w, " "));
try!(write!(w, " "));
v += char_step;
c += 1;
}

if_ok!(write!(w, "| {}", histr));
try!(write!(w, "| {}", histr));
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions src/libnative/io/pipe_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl Drop for Inner {
}

fn connect(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
let (addr, len) = if_ok!(addr_to_sockaddr_un(addr));
let inner = Inner { fd: if_ok!(unix_socket(ty)) };
let (addr, len) = try!(addr_to_sockaddr_un(addr));
let inner = Inner { fd: try!(unix_socket(ty)) };
let addrp = &addr as *libc::sockaddr_storage;
match retry(|| unsafe {
libc::connect(inner.fd, addrp as *libc::sockaddr,
Expand All @@ -90,8 +90,8 @@ fn connect(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
}

fn bind(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
let (addr, len) = if_ok!(addr_to_sockaddr_un(addr));
let inner = Inner { fd: if_ok!(unix_socket(ty)) };
let (addr, len) = try!(addr_to_sockaddr_un(addr));
let inner = Inner { fd: try!(unix_socket(ty)) };
let addrp = &addr as *libc::sockaddr_storage;
match unsafe {
libc::bind(inner.fd, addrp as *libc::sockaddr, len as libc::socklen_t)
Expand Down Expand Up @@ -198,7 +198,7 @@ impl UnixDatagram {
}

pub fn sendto(&mut self, buf: &[u8], dst: &CString) -> IoResult<()> {
let (dst, len) = if_ok!(addr_to_sockaddr_un(dst));
let (dst, len) = try!(addr_to_sockaddr_un(dst));
let dstp = &dst as *libc::sockaddr_storage;
let ret = retry(|| unsafe {
libc::sendto(self.fd(),
Expand Down
Loading