From 950a720a5c0b43199877b3727f0d06412f8a12fb Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 17:11:53 -0700 Subject: Modularization --- src/lib.rs | 63 +++++++++----------------------------------------------------- 1 file changed, 9 insertions(+), 54 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index e3395e9..4e630d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,50 +1,4 @@ -use std::os::raw::{c_char, c_void}; -use std::ffi::CString; - -/// # TIFF Internal Structure -/// An opaque type -#[repr(C)] -pub struct TIFF { - _unused: [u8; 0], -} - -/// # TIFF Warning Handler Definition -pub type TIFFWarningHandler = Option; - -/// # TIFF Ignore Warnings Handle -unsafe extern "C" fn tiff_ignore_warning_handle(_module: *const c_char, _fmt: *const c_char, _ap: *mut std::ffi::c_void) { - // Do nothing -} - -#[link(name = "tiff")] -unsafe extern "C" { - pub fn TIFFSetWarningHandler(handler: TIFFWarningHandler) -> TIFFWarningHandler; - pub fn TIFFOpen(filename: *const c_char, mode: *const c_char) -> *mut TIFF; - pub fn TIFFClose(tiff_ptr: *mut TIFF); -} - -/// # Ignore TIFF Warnings -pub fn tiff_ignore_warnings() { - unsafe { - let _ = TIFFSetWarningHandler(Some(tiff_ignore_warning_handle)); - } -} - -/// # Open TIFF File -pub fn tiff_open(filename: &str) -> *mut TIFF { - let c_filename = CString::new(filename).expect("Cast error"); - let c_mode = CString::new("r").expect("Cast error"); - unsafe { - TIFFOpen(c_filename.as_ptr(), c_mode.as_ptr()) - } -} - -/// # Close TIFF File -pub fn tiff_close(tiff_ptr: *mut TIFF) { - unsafe { - TIFFClose(tiff_ptr); - } -} +mod tiff; #[cfg(test)] mod tests { @@ -57,16 +11,17 @@ mod tests { #[test] fn ignore_warning_test() { - tiff_ignore_warnings(); - assert_eq!(1, 1); + tiff::ignore_warnings(); + assert_eq!(0, 0); } #[test] fn tiff_open_test() { - tiff_ignore_warnings(); - let result = tiff_open("../test.tif"); - assert!(!result.is_null()); - tiff_close(result); - assert_eq!(1, 1); + tiff::ignore_warnings(); + if let Some(result) = tiff::open("../test.tif") { + tiff::close(result); + } else { + assert!(false); + } } } -- cgit v1.2.1