Redesign types module
Now we are using more functionality given to us by rust-bindgen instead of maintaining enum mappings ourselves: * Rustified enums can be generated automatically by using the EnumVariation::Rust style in rust-bindgen * Redundant suffixes can be removed through implementing ParseCallbacks::enum_variant_name * The redundant FromRust trait was removed and replaced with the standard From and Into traits
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@ -34,7 +34,6 @@ extern crate libc;
|
||||
|
||||
use libc::size_t;
|
||||
|
||||
pub use conversions::ToMagick;
|
||||
pub use result::MagickError;
|
||||
use result::Result;
|
||||
pub use types::*;
|
||||
@ -51,7 +50,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
pub fn magick_wand_genesis() {
|
||||
unsafe {
|
||||
match bindings::IsMagickWandInstantiated() {
|
||||
bindings::MagickBooleanType_MagickTrue => (),
|
||||
bindings::MagickBooleanType::MagickTrue => (),
|
||||
_ => bindings::MagickWandGenesis(),
|
||||
}
|
||||
}
|
||||
@ -61,7 +60,7 @@ pub fn magick_wand_genesis() {
|
||||
/// This function is safe to be called repeatedly.
|
||||
pub fn magick_wand_terminus() {
|
||||
unsafe {
|
||||
if let bindings::MagickBooleanType_MagickTrue = bindings::IsMagickWandInstantiated() {
|
||||
if let bindings::MagickBooleanType::MagickTrue = bindings::IsMagickWandInstantiated() {
|
||||
bindings::MagickWandTerminus();
|
||||
}
|
||||
}
|
||||
@ -69,7 +68,7 @@ pub fn magick_wand_terminus() {
|
||||
|
||||
pub fn magick_query_fonts(pattern: &str) -> Result<Vec<String>> {
|
||||
let mut number_fonts: size_t = 0;
|
||||
let c_string = ::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() {
|
||||
@ -78,9 +77,9 @@ pub fn magick_query_fonts(pattern: &str) -> Result<Vec<String>> {
|
||||
))
|
||||
} else {
|
||||
let mut v = Vec::new();
|
||||
let c_str_ptr_slice = unsafe { ::std::slice::from_raw_parts(ptr, number_fonts as usize) };
|
||||
let c_str_ptr_slice = unsafe { std::slice::from_raw_parts(ptr, number_fonts as usize) };
|
||||
for c_str_ptr in c_str_ptr_slice {
|
||||
let c_str = unsafe { ::std::ffi::CStr::from_ptr(*c_str_ptr) };
|
||||
let c_str = unsafe { std::ffi::CStr::from_ptr(*c_str_ptr) };
|
||||
v.push(c_str.to_string_lossy().into_owned())
|
||||
}
|
||||
Ok(v)
|
||||
|
||||
Reference in New Issue
Block a user