remove use of deprecated item 'try': use the ? operator instead

Signed-off-by: Nikola Pajkovsky <nikola.pajkovsky@livesporttv.cz>
This commit is contained in:
Nikola Pajkovsky 2020-05-21 12:11:15 +02:00
parent 415ad30bd0
commit 51b2cac594
5 changed files with 33 additions and 34 deletions

View file

@ -69,8 +69,7 @@ pub fn magick_wand_terminus() {
pub fn magick_query_fonts(pattern: &str) -> Result<Vec<String>, &'static str> {
let mut number_fonts: size_t = 0;
let c_string =
try!(::std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring"));
let c_string = ::std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring")?;
let ptr =
unsafe { bindings::MagickQueryFonts(c_string.as_ptr(), &mut number_fonts as *mut size_t) };
if ptr.is_null() {

View file

@ -35,7 +35,7 @@ wand_common!(
impl DrawingWand {
pub fn draw_annotation(&mut self, x: f64, y: f64, text: &str) -> Result<(), &'static str> {
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
let c_string = CString::new(text).map_err(|_| "could not convert to cstring")?;
unsafe { bindings::DrawAnnotation(self.wand, x, y, c_string.as_ptr() as *const _) };
Ok(())
}
@ -94,13 +94,13 @@ impl DrawingWand {
impl fmt::Debug for DrawingWand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "DrawingWand {{"));
try!(writeln!(f, " Exception: {:?}", self.get_exception()));
try!(writeln!(f, " IsWand: {:?}", self.is_wand()));
try!(self.fmt_unchecked_settings(f, " "));
try!(self.fmt_string_settings(f, " "));
try!(self.fmt_string_unchecked_settings(f, " "));
try!(self.fmt_pixel_settings(f, " "));
writeln!(f, "DrawingWand {{")?;
writeln!(f, " Exception: {:?}", self.get_exception())?;
writeln!(f, " IsWand: {:?}", self.is_wand())?;
self.fmt_unchecked_settings(f, " ")?;
self.fmt_string_settings(f, " ")?;
self.fmt_string_unchecked_settings(f, " ")?;
self.fmt_pixel_settings(f, " ")?;
writeln!(f, "}}")
}
}

View file

@ -118,7 +118,7 @@ macro_rules! set_get {
}
)*
pub fn fmt_checked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
Ok(())
}
}
@ -135,7 +135,7 @@ macro_rules! set_get_unchecked {
}
)*
pub fn fmt_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get()); )*
Ok(())
}
}
@ -154,7 +154,7 @@ macro_rules! string_get {
Ok(result)
}
}
}
};
}
macro_rules! string_set_get {
@ -162,7 +162,7 @@ macro_rules! string_set_get {
$(
string_get!($get, $c_get);
pub fn $set(&mut self, s: &str) -> Result<(), &'static str> {
let c_string = try!(::std::ffi::CString::new(s).map_err(|_| "could not convert to cstring"));
let c_string = std::ffi::CString::new(s).map_err(|_| "could not convert to cstring")?;
match unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) } {
::bindings::MagickBooleanType_MagickTrue => Ok(()),
_ => Err(concat!(stringify!($set), " returned false"))
@ -170,7 +170,7 @@ macro_rules! string_set_get {
}
)*
pub fn fmt_string_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
Ok(())
}
}
@ -181,13 +181,13 @@ macro_rules! string_set_get_unchecked {
$(
string_get!($get, $c_get);
pub fn $set(&mut self, s: &str) -> Result<(), &'static str> {
let c_string = try!(::std::ffi::CString::new(s).map_err(|_| "could not convert to cstring"));
let c_string = ::std::ffi::CString::new(s).map_err(|_| "could not convert to cstring")?;
unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) };
Ok(())
}
)*
pub fn fmt_string_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
Ok(())
}
}
@ -207,8 +207,8 @@ macro_rules! pixel_set_get {
)*
pub fn fmt_pixel_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
$(
try!(writeln!(f, "{}{:<50}: ", prefix, stringify!($c_get)));
try!(self.$get().fmt_w_prefix(f, &format!("{}{:<53}", prefix, " ") ));
writeln!(f, "{}{:<50}: ", prefix, stringify!($c_get))?;
self.$get().fmt_w_prefix(f, &format!("{}{:<53}", prefix, " ") )?;
)*
Ok(())
}
@ -235,14 +235,14 @@ macro_rules! color_set_get {
}
)*
pub fn fmt_color_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
try!(writeln!(f, "{}Color: {:?}, normalized: {:?}\n{}hsl: {:?}",
writeln!(f, "{}Color: {:?}, normalized: {:?}\n{}hsl: {:?}",
prefix,
self.get_color_as_string(),
self.get_color_as_normalized_string(),
prefix,
self.get_hsl()
));
$( try!(writeln!(f, "{}{:<10}: {:>} quantum: {}", prefix, stringify!($c_get).split_at(8).1, self.$get(), self.$get_quantum())); )*
)?;
$( writeln!(f, "{}{:<10}: {:>} quantum: {}", prefix, stringify!($c_get).split_at(8).1, self.$get(), self.$get_quantum())?; )*
Ok(())
}
}

View file

@ -75,7 +75,7 @@ impl MagickWand {
angle: f64,
text: &str,
) -> Result<(), &'static str> {
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
let c_string = CString::new(text).map_err(|_| "could not convert to cstring")?;
match unsafe {
bindings::MagickAnnotateImage(
self.wand,
@ -841,11 +841,11 @@ impl MagickWand {
impl fmt::Debug for MagickWand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "MagickWand {{"));
try!(writeln!(f, " Exception: {:?}", self.get_exception()));
try!(writeln!(f, " IsWand: {:?}", self.is_wand()));
try!(self.fmt_string_settings(f, " "));
try!(self.fmt_checked_settings(f, " "));
writeln!(f, "MagickWand {{")?;
writeln!(f, " Exception: {:?}", self.get_exception())?;
writeln!(f, " IsWand: {:?}", self.is_wand())?;
self.fmt_string_settings(f, " ")?;
self.fmt_checked_settings(f, " ")?;
writeln!(f, "}}")
}
}

View file

@ -70,16 +70,16 @@ impl PixelWand {
pub fn fmt_w_prefix(&self, f: &mut fmt::Formatter, prefix: &str) -> fmt::Result {
let mut prf = prefix.to_string();
prf.push_str(" ");
try!(writeln!(f, "{}PixelWand {{", prefix));
try!(writeln!(f, "{}Exception: {:?}", prf, self.get_exception()));
try!(writeln!(f, "{}IsWand: {:?}", prf, self.is_wand()));
try!(self.fmt_unchecked_settings(f, &prf));
try!(self.fmt_color_settings(f, &prf));
writeln!(f, "{}PixelWand {{", prefix)?;
writeln!(f, "{}Exception: {:?}", prf, self.get_exception())?;
writeln!(f, "{}IsWand: {:?}", prf, self.is_wand())?;
self.fmt_unchecked_settings(f, &prf)?;
self.fmt_color_settings(f, &prf)?;
writeln!(f, "{}}}", prefix)
}
pub fn set_color(&mut self, s: &str) -> Result<(), &'static str> {
let c_string = try!(CString::new(s).map_err(|_| "could not convert to cstring"));
let c_string = CString::new(s).map_err(|_| "could not convert to cstring")?;
match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()),
_ => Err("failed to set color"),