- replace anyhow with custom error type
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::error::Error;
|
||||
use crate::handle::{InputStream, MemoryAllocation};
|
||||
use crate::misc::{PixelType, Ptr};
|
||||
use crate::sys::*;
|
||||
use anyhow::{Error, Result};
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::{CStr, CString, c_char, c_void};
|
||||
use std::fmt::Debug;
|
||||
use std::mem;
|
||||
@@ -203,17 +204,17 @@ impl LibCZIVersionInfo {
|
||||
}
|
||||
|
||||
impl LibCZIBuildInformation {
|
||||
pub fn get_compiler_information(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.compilerIdentification) }.to_str()?)
|
||||
pub fn get_compiler_information(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.compilerIdentification) }.to_string_lossy()
|
||||
}
|
||||
pub fn get_repository_url(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.repositoryUrl) }.to_str()?)
|
||||
pub fn get_repository_url(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.repositoryUrl) }.to_string_lossy()
|
||||
}
|
||||
pub fn get_repository_branch(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.repositoryBranch) }.to_str()?)
|
||||
pub fn get_repository_branch(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.repositoryBranch) }.to_string_lossy()
|
||||
}
|
||||
pub fn get_repository_tag(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.repositoryTag) }.to_str()?)
|
||||
pub fn get_repository_tag(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.repositoryTag) }.to_string_lossy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,11 +230,11 @@ impl Drop for LibCZIBuildInformation {
|
||||
}
|
||||
|
||||
impl InputStreamClassInfo {
|
||||
pub fn get_name(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.name) }.to_str()?)
|
||||
pub fn get_name(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.name) }.to_string_lossy()
|
||||
}
|
||||
pub fn get_description(&self) -> Result<&str> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.description) }.to_str()?)
|
||||
pub fn get_description(&'_ self) -> Cow<'_, str> {
|
||||
unsafe { CStr::from_ptr(self.0.description) }.to_string_lossy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,7 +567,7 @@ impl SubBlockStatisticsEx {
|
||||
}
|
||||
|
||||
impl MetadataAsXml {
|
||||
pub fn get_data(&self) -> Result<String> {
|
||||
pub fn get_data(&self) -> Result<String, Error> {
|
||||
let xml_data = unsafe {
|
||||
Vec::from_raw_parts(
|
||||
self.0.data as *mut u8,
|
||||
@@ -589,7 +590,7 @@ impl Drop for MetadataAsXml {
|
||||
impl TryFrom<&MetadataAsXml> for String {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: &MetadataAsXml) -> std::result::Result<Self, Self::Error> {
|
||||
fn try_from(value: &MetadataAsXml) -> Result<Self, Self::Error> {
|
||||
value.get_data()
|
||||
}
|
||||
}
|
||||
@@ -608,7 +609,7 @@ impl BitmapInfo {
|
||||
pub fn get_height(&self) -> u32 {
|
||||
self.0.height
|
||||
}
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType> {
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType, Error> {
|
||||
PixelType::try_from(self.0.pixelType)
|
||||
}
|
||||
pub fn set_width(&mut self, width: u32) {
|
||||
@@ -666,7 +667,7 @@ impl SubBlockInfo {
|
||||
pub fn get_compression_mode_raw(&self) -> i32 {
|
||||
self.0.compression_mode_raw
|
||||
}
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType> {
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType, Error> {
|
||||
PixelType::try_from(self.0.pixel_type)
|
||||
}
|
||||
pub fn get_coordinate(&self) -> Coordinate {
|
||||
@@ -708,7 +709,7 @@ impl AttachmentInfo {
|
||||
pub fn get_content_file_type(&self) -> [u8; 9] {
|
||||
self.0.content_file_type
|
||||
}
|
||||
pub fn get_name(&self) -> Result<String> {
|
||||
pub fn get_name(&self) -> Result<String, Error> {
|
||||
Ok(
|
||||
CStr::from_bytes_until_nul(&self.0.name.iter().map(|&i| i as u8).collect::<Vec<_>>())?
|
||||
.to_str()?
|
||||
@@ -718,7 +719,7 @@ impl AttachmentInfo {
|
||||
pub fn get_name_overflow(&self) -> bool {
|
||||
self.0.name_overflow
|
||||
}
|
||||
pub fn get_name_in_case_of_overflow(&self) -> Result<String> {
|
||||
pub fn get_name_in_case_of_overflow(&self) -> Result<String, Error> {
|
||||
Ok(
|
||||
unsafe { CString::from_raw(self.0.name_in_case_of_overflow as *mut c_char) }
|
||||
.to_str()?
|
||||
@@ -833,7 +834,7 @@ impl AddSubBlockInfo {
|
||||
pub fn get_physical_height(&self) -> i32 {
|
||||
self.0.physical_height
|
||||
}
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType> {
|
||||
pub fn get_pixel_type(&self) -> Result<PixelType, Error> {
|
||||
PixelType::try_from(self.0.pixel_type)
|
||||
}
|
||||
pub fn get_compression_mode_raw(&self) -> i32 {
|
||||
@@ -1013,7 +1014,7 @@ impl AccessorOptions {
|
||||
sort_by_m: bool,
|
||||
use_visibility_check_optimization: bool,
|
||||
additional_parameters: S,
|
||||
) -> Result<Self> {
|
||||
) -> Result<Self, Error> {
|
||||
let additional_parameters =
|
||||
ManuallyDrop::new(CString::new(additional_parameters.as_ref())?);
|
||||
Ok(Self(AccessorOptionsInterop {
|
||||
@@ -1040,7 +1041,7 @@ impl AccessorOptions {
|
||||
pub fn get_use_visibility_check_optimization(&self) -> bool {
|
||||
self.0.use_visibility_check_optimization
|
||||
}
|
||||
pub fn get_additional_parameters(&self) -> Result<String> {
|
||||
pub fn get_additional_parameters(&self) -> Result<String, Error> {
|
||||
Ok(unsafe { CStr::from_ptr(self.0.additional_parameters) }
|
||||
.to_str()?
|
||||
.to_string())
|
||||
@@ -1066,7 +1067,7 @@ impl AccessorOptions {
|
||||
pub fn set_additional_parameters<S: AsRef<str>>(
|
||||
&mut self,
|
||||
additional_parameters: S,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), Error> {
|
||||
let additional_parameters =
|
||||
ManuallyDrop::new(CString::new(additional_parameters.as_ref())?);
|
||||
self.0.additional_parameters = additional_parameters.as_ptr();
|
||||
|
||||
Reference in New Issue
Block a user