Skip to content

Commit c59d3e6

Browse files
committed
Replace try macros with ? operator
1 parent 0a9b18b commit c59d3e6

File tree

3 files changed

+78
-93
lines changed

3 files changed

+78
-93
lines changed

src/ewkb.rs

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ pub trait EwkbRead: fmt::Debug + Sized {
6767
}
6868

6969
fn read_ewkb<R: Read>(raw: &mut R) -> Result<Self, Error> {
70-
let byte_order = try!(raw.read_i8());
70+
let byte_order = raw.read_i8()?;
7171
let is_be = byte_order == 0i8;
7272

73-
let type_id = try!(read_u32(raw, is_be));
73+
let type_id = read_u32(raw, is_be)?;
7474
let mut srid: Option<i32> = None;
7575
if type_id & 0x20000000 == 0x20000000 {
76-
srid = Some(try!(read_i32(raw, is_be)));
76+
srid = Some(read_i32(raw, is_be)?);
7777
}
7878
Self::read_ewkb_body(raw, is_be, srid)
7979
}
@@ -107,11 +107,11 @@ pub trait EwkbWrite: fmt::Debug + Sized {
107107

108108
fn write_ewkb<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
109109
// use LE
110-
try!(w.write_u8(0x01));
110+
w.write_u8(0x01)?;
111111
let type_id = self.type_id();
112-
try!(w.write_u32::<LittleEndian>(type_id));
112+
w.write_u32::<LittleEndian>(type_id)?;
113113
self.opt_srid().map(|srid| w.write_i32::<LittleEndian>(srid));
114-
try!(self.write_ewkb_body(w));
114+
self.write_ewkb_body(w)?;
115115
Ok(())
116116
}
117117
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error>;
@@ -259,15 +259,15 @@ macro_rules! impl_point_read_traits {
259259
self.srid = srid;
260260
}
261261
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, srid: Option<i32>) -> Result<Self, Error> {
262-
let x = try!(read_f64(raw, is_be));
263-
let y = try!(read_f64(raw, is_be));
262+
let x = read_f64(raw, is_be)?;
263+
let y = read_f64(raw, is_be)?;
264264
let z = if Self::has_z() {
265-
Some(try!(read_f64(raw, is_be)))
265+
Some(read_f64(raw, is_be)?)
266266
} else {
267267
None
268268
};
269269
let m = if Self::has_m() {
270-
Some(try!(read_f64(raw, is_be)))
270+
Some(read_f64(raw, is_be)?)
271271
} else {
272272
None
273273
};
@@ -301,7 +301,7 @@ pub trait AsEwkbPoint<'a> {
301301

302302
impl<'a> fmt::Debug for EwkbPoint<'a> {
303303
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
304-
try!(write!(f, "EwkbPoint")); //TODO
304+
write!(f, "EwkbPoint")?; //TODO
305305
Ok(())
306306
}
307307
}
@@ -314,29 +314,14 @@ impl<'a> EwkbWrite for EwkbPoint<'a> {
314314
self.srid
315315
}
316316
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
317-
try!(w.write_f64::<LittleEndian>(self.geom.x()));
318-
try!(w.write_f64::<LittleEndian>(self.geom.y()));
317+
w.write_f64::<LittleEndian>(self.geom.x())?;
318+
w.write_f64::<LittleEndian>(self.geom.y())?;
319319
self.geom.opt_z().map(|z| w.write_f64::<LittleEndian>(z));
320320
self.geom.opt_m().map(|m| w.write_f64::<LittleEndian>(m));
321321
Ok(())
322322
}
323323
}
324324

325-
/*
326-
impl EwkbWrite for Point {
327-
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
328-
//lol
329-
let x = unsafe { *mem::transmute::<_, *const f64>(self) };
330-
let y = unsafe { *mem::transmute::<_, *const f64>(self).offset(1) };
331-
try!(w.write_f64::<LittleEndian>(x));
332-
try!(w.write_f64::<LittleEndian>(y));
333-
self.opt_z().map(|z| w.write_f64::<LittleEndian>(z));
334-
self.opt_m().map(|m| w.write_f64::<LittleEndian>(m));
335-
Ok(())
336-
}
337-
}
338-
*/
339-
340325

341326
macro_rules! point_container_type {
342327
// geometries containing points
@@ -441,7 +426,7 @@ macro_rules! impl_read_for_point_container_type {
441426
}
442427
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, srid: Option<i32>) -> Result<Self, Error> {
443428
let mut points: Vec<P> = vec![];
444-
let size = try!(read_u32(raw, is_be)) as usize;
429+
let size = read_u32(raw, is_be)? as usize;
445430
for _ in 0..size {
446431
points.push(P::read_ewkb_body(raw, is_be, srid)?);
447432
}
@@ -462,7 +447,7 @@ macro_rules! impl_read_for_point_container_type {
462447
}
463448
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, srid: Option<i32>) -> Result<Self, Error> {
464449
let mut points: Vec<P> = vec![];
465-
let size = try!(read_u32(raw, is_be)) as usize;
450+
let size = read_u32(raw, is_be)? as usize;
466451
for _ in 0..size {
467452
points.push(P::read_ewkb(raw)?);
468453
}
@@ -485,7 +470,7 @@ macro_rules! impl_read_for_geometry_container_type {
485470
}
486471
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, srid: Option<i32>) -> Result<Self, Error> {
487472
let mut $itemname: Vec<$itemtype<P>> = vec![];
488-
let size = try!(read_u32(raw, is_be)) as usize;
473+
let size = read_u32(raw, is_be)? as usize;
489474
for _ in 0..size {
490475
$itemname.push($itemtype::read_ewkb_body(raw, is_be, srid)?);
491476
}
@@ -505,7 +490,7 @@ macro_rules! impl_read_for_geometry_container_type {
505490
}
506491
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, srid: Option<i32>) -> Result<Self, Error> {
507492
let mut $itemname: Vec<$itemtype<P>> = vec![];
508-
let size = try!(read_u32(raw, is_be)) as usize;
493+
let size = read_u32(raw, is_be)? as usize;
509494
for _ in 0..size {
510495
$itemname.push($itemtype::read_ewkb(raw)?);
511496
}
@@ -538,7 +523,7 @@ macro_rules! point_container_write {
538523
I: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
539524
{
540525
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
541-
try!(write!(f, "$ewkbtype")); //TODO
526+
write!(f, "$ewkbtype")?; //TODO
542527
Ok(())
543528
}
544529
}
@@ -556,10 +541,10 @@ macro_rules! point_container_write {
556541
}
557542

558543
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
559-
try!(w.write_u32::<LittleEndian>(self.geom.points().len() as u32));
544+
w.write_u32::<LittleEndian>(self.geom.points().len() as u32)?;
560545
for geom in self.geom.points() {
561546
let wkb = EwkbPoint { geom: geom, srid: None, point_type: self.point_type.clone() };
562-
try!(wkb.$writecmd(w));
547+
wkb.$writecmd(w)?;
563548
}
564549
Ok(())
565550
}
@@ -606,7 +591,7 @@ macro_rules! geometry_container_write {
606591
J: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
607592
{
608593
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
609-
try!(write!(f, "$ewkbtype")); //TODO
594+
write!(f, "$ewkbtype")?; //TODO
610595
Ok(())
611596
}
612597
}
@@ -626,10 +611,10 @@ macro_rules! geometry_container_write {
626611
}
627612

628613
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
629-
try!(w.write_u32::<LittleEndian>(self.geom.$itemname().len() as u32));
614+
w.write_u32::<LittleEndian>(self.geom.$itemname().len() as u32)?;
630615
for geom in self.geom.$itemname() {
631616
let wkb = $ewkbitemtype { geom: geom, srid: None, point_type: self.point_type.clone() };
632-
try!(wkb.$writecmd(w));
617+
wkb.$writecmd(w)?;
633618
}
634619
Ok(())
635620
}
@@ -680,7 +665,7 @@ macro_rules! geometry_container_write {
680665
J: 'a + Iterator<Item=&'a T> + ExactSizeIterator<Item=&'a T>
681666
{
682667
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
683-
try!(write!(f, "$ewkbtype")); //TODO
668+
write!(f, "$ewkbtype")?; //TODO
684669
Ok(())
685670
}
686671
}
@@ -702,10 +687,10 @@ macro_rules! geometry_container_write {
702687
}
703688

704689
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
705-
try!(w.write_u32::<LittleEndian>(self.geom.$itemname().len() as u32));
690+
w.write_u32::<LittleEndian>(self.geom.$itemname().len() as u32)?;
706691
for geom in self.geom.$itemname() {
707692
let wkb = $ewkbitemtype { geom: geom, srid: None, point_type: self.point_type.clone() };
708-
try!(wkb.$writecmd(w));
693+
wkb.$writecmd(w)?;
709694
}
710695
Ok(())
711696
}
@@ -813,13 +798,13 @@ impl<P> EwkbRead for GeometryT<P>
813798
P::point_type()
814799
}
815800
fn read_ewkb<R: Read>(raw: &mut R) -> Result<Self, Error> {
816-
let byte_order = try!(raw.read_i8());
801+
let byte_order = raw.read_i8()?;
817802
let is_be = byte_order == 0i8;
818803

819-
let type_id = try!(read_u32(raw, is_be));
804+
let type_id = read_u32(raw, is_be)?;
820805
let mut srid: Option<i32> = None;
821806
if type_id & 0x20000000 == 0x20000000 {
822-
srid = Some(try!(read_i32(raw, is_be)));
807+
srid = Some(read_i32(raw, is_be)?);
823808
}
824809

825810
let geom = match type_id & 0xff {
@@ -867,14 +852,14 @@ impl<P> EwkbRead for GeometryCollectionT<P>
867852
}
868853
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, _srid: Option<i32>) -> Result<Self, Error> {
869854
let mut ret = GeometryCollectionT::new();
870-
let size = try!(read_u32(raw, is_be)) as usize;
855+
let size = read_u32(raw, is_be)? as usize;
871856
for _ in 0..size {
872-
let is_be = try!(raw.read_i8()) == 0i8;
857+
let is_be = raw.read_i8()? == 0i8;
873858

874-
let type_id = try!(read_u32(raw, is_be));
859+
let type_id = read_u32(raw, is_be)?;
875860
let mut srid: Option<i32> = None;
876861
if type_id & 0x20000000 == 0x20000000 {
877-
srid = Some(try!(read_i32(raw, is_be)));
862+
srid = Some(read_i32(raw, is_be)?);
878863
}
879864
let geom = match type_id & 0xff {
880865
0x01 => GeometryT::Point(P::read_ewkb_body(raw, is_be, srid)?),

src/postgis.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'a> ToSql for ewkb::EwkbPoint<'a> {
2727
to_sql_checked!();
2828
accepts_geography!();
2929
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
30-
try!(self.write_ewkb(out));
30+
self.write_ewkb(out)?;
3131
Ok(IsNull::No)
3232
}
3333
}
@@ -46,7 +46,7 @@ macro_rules! impl_sql_for_point_type {
4646
to_sql_checked!();
4747
accepts_geography!();
4848
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
49-
try!(self.as_ewkb().write_ewkb(out));
49+
self.as_ewkb().write_ewkb(out)?;
5050
Ok(IsNull::No)
5151
}
5252
}
@@ -77,7 +77,7 @@ macro_rules! impl_sql_for_geom_type {
7777
to_sql_checked!();
7878
accepts_geography!();
7979
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
80-
try!(self.as_ewkb().write_ewkb(out));
80+
self.as_ewkb().write_ewkb(out)?;
8181
Ok(IsNull::No)
8282
}
8383
}
@@ -100,7 +100,7 @@ macro_rules! impl_sql_for_ewkb_type {
100100
to_sql_checked!();
101101
accepts_geography!();
102102
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
103-
try!(self.write_ewkb(out));
103+
self.write_ewkb(out)?;
104104
Ok(IsNull::No)
105105
}
106106
}
@@ -115,7 +115,7 @@ macro_rules! impl_sql_for_ewkb_type {
115115
to_sql_checked!();
116116
accepts_geography!();
117117
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
118-
try!(self.write_ewkb(out));
118+
self.write_ewkb(out)?;
119119
Ok(IsNull::No)
120120
}
121121
}
@@ -132,7 +132,7 @@ macro_rules! impl_sql_for_ewkb_type {
132132
to_sql_checked!();
133133
accepts_geography!();
134134
fn to_sql(&self, _: &Type, out: &mut Vec<u8>, _ctx: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
135-
try!(self.write_ewkb(out));
135+
self.write_ewkb(out)?;
136136
Ok(IsNull::No)
137137
}
138138
}

0 commit comments

Comments
 (0)