diff --git a/Cargo.toml b/Cargo.toml index 87243ac..e201109 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "klamath_rs_ext" version = "0.2.0" authors = ["jan "] -edition = "2021" +edition = "2024" [lib] diff --git a/src/basic.rs b/src/basic.rs index 8bad4e7..051d0ba 100644 --- a/src/basic.rs +++ b/src/basic.rs @@ -15,15 +15,15 @@ pub enum ErrType { Failed(String), } -pub fn fail(input: &[u8], msg: String) -> IResult { +pub fn fail(input: &[u8], msg: String) -> IResult<'_, O> { Err((input, ErrType::Failed(msg))) } -pub fn incomplete(input: &[u8], size: Option) -> IResult { +pub fn incomplete(input: &[u8], size: Option) -> IResult<'_, O> { Err((input, ErrType::Incomplete(size))) } -pub fn take_bytes>(input: &[u8], count: CC) -> IResult<&[u8]> { +pub fn take_bytes>(input: &[u8], count: CC) -> IResult<'_, &[u8]> { let cc = count.into(); if input.len() < cc { incomplete(input, Some(cc)) @@ -37,19 +37,19 @@ pub fn take_bytes>(input: &[u8], count: CC) -> IResult<&[u8]> { /* * Parse functions */ -pub fn parse_u16(input: &[u8]) -> IResult { +pub fn parse_u16(input: &[u8]) -> IResult<'_, u16> { let (input, buf) = take_bytes(input, 2_usize)?; let val = BigEndian::read_u16(buf); Ok((input, val)) } -pub fn parse_int2(input: &[u8]) -> IResult { +pub fn parse_int2(input: &[u8]) -> IResult<'_, i16> { let (input, buf) = take_bytes(input, 2_usize)?; let val = BigEndian::read_i16(buf); Ok((input, val)) } -pub fn parse_int4(input: &[u8]) -> IResult { +pub fn parse_int4(input: &[u8]) -> IResult<'_, i32> { let (input, buf) = take_bytes(input, 4_usize)?; let val = BigEndian::read_i32(buf); Ok((input, val)) @@ -67,14 +67,14 @@ pub fn decode_real8(int: u64) -> f64 { mant * 2_f64.powi(exp2) } -pub fn parse_real8(input: &[u8]) -> IResult { +pub fn parse_real8(input: &[u8]) -> IResult<'_, f64> { let (input, buf) = take_bytes(input, 8_usize)?; let data = BigEndian::read_u64(buf); Ok((input, decode_real8(data))) } -pub fn parse_datetime(input: &[u8]) -> IResult<[i16; 6]> { +pub fn parse_datetime(input: &[u8]) -> IResult<'_, [i16; 6]> { let mut buf = [0_i16; 6]; let mut input = input; for bb in &mut buf { @@ -85,7 +85,7 @@ pub fn parse_datetime(input: &[u8]) -> IResult<[i16; 6]> { } -pub fn parse_bitarray(input: &[u8]) -> IResult<[bool; 16]> { +pub fn parse_bitarray(input: &[u8]) -> IResult<'_, [bool; 16]> { let mut bits = [false; 16]; let (input, val) = parse_int2(input)?; for (ii, bit) in bits.iter_mut().enumerate() { @@ -95,7 +95,7 @@ pub fn parse_bitarray(input: &[u8]) -> IResult<[bool; 16]> { } -pub fn parse_ascii(input: &[u8], length: u16) -> IResult> { +pub fn parse_ascii(input: &[u8], length: u16) -> IResult<'_, Vec> { let length = length as usize; let (input, data) = take_bytes(input, length)?; let last = data[length - 1]; diff --git a/src/elements.rs b/src/elements.rs index f44059c..e42e3f8 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -946,7 +946,7 @@ pub trait Element { /// Read from a stream to construct this object. /// Consumes up to (and including) the ENDEL record. /// - fn read(input: &[u8]) -> IResult where Self: Sized; + fn read(input: &[u8]) -> IResult<'_, Self> where Self: Sized; /// /// Write this element to a stream. @@ -993,7 +993,7 @@ pub struct Reference { } impl Element for Reference { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let mut invert_y = false; let mut mag = 1.0; let mut angle_deg = 0.0; @@ -1094,7 +1094,7 @@ pub struct Boundary { } impl Element for Boundary { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let (input, layer) = LAYER::skip_and_read(input)?; let (input, dtype) = DATATYPE::read(input)?; let (input, xy) = XY::read(input)?; @@ -1142,7 +1142,7 @@ pub struct Path { } impl Element for Path { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let mut path_type = 0; let mut width = 0; let mut bgn_ext = 0; @@ -1221,7 +1221,7 @@ pub struct GDSBox { } impl Element for GDSBox { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let (input, layer) = LAYER::skip_and_read(input)?; let (input, dtype) = BOXTYPE::read(input)?; let (input, xy) = XY::read(input)?; @@ -1260,7 +1260,7 @@ pub struct Node { } impl Element for Node { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let (input, layer) = LAYER::skip_and_read(input)?; let (input, dtype) = NODETYPE::read(input)?; let (input, xy) = XY::read(input)?; @@ -1317,7 +1317,7 @@ pub struct Text { } impl Element for Text { - fn read(input: &[u8]) -> IResult { + fn read(input: &[u8]) -> IResult<'_, Self> { let mut path_type = 0; let mut presentation = [false; 16]; let mut invert_y = false; diff --git a/src/lib.rs b/src/lib.rs index 78e359b..39081ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ use arrow::ffi::{to_ffi, FFI_ArrowArray, FFI_ArrowSchema}; use arrow::array::Array; -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn read_path( cpath: *const c_char, arr: *mut FFI_ArrowArray, @@ -40,7 +40,7 @@ pub unsafe extern "C" fn read_path( let input = fs::read(path).expect("File read failed"); let (_input, struct_arr) = read_library(&input).expect("Read failed"); - (*arr, *schema) = to_ffi(&struct_arr.to_data()).unwrap(); + unsafe { (*arr, *schema) = to_ffi(&struct_arr.to_data()).unwrap(); } } @@ -80,40 +80,40 @@ macro_rules! impl_i32be { } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn f64_to_i16(arr: *mut f64, size: usize) -> f64 { impl_i16be!(f64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn f64_to_i32(arr: *mut f64, size: usize) -> f64 { impl_i32be!(f64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn f32_to_i16(arr: *mut f32, size: usize) -> f32 { impl_i16be!(f32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn f32_to_i32(arr: *mut f32, size: usize) -> f32 { impl_i32be!(f32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn u64_to_i16(arr: *mut u64, size: usize) -> u64 { impl_i16be!(u64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn u64_to_i32(arr: *mut u64, size: usize) -> u64 { impl_i32be!(u64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn i64_to_i16(arr: *mut i64, size: usize) -> i64 { impl_i16be!(i64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn i64_to_i32(arr: *mut i64, size: usize) -> i64 { impl_i32be!(i64, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn u32_to_i16(arr: *mut u32, size: usize) -> u32 { impl_i16be!(u32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn u32_to_i32(arr: *mut u32, size: usize) -> u32 { impl_i32be!(u32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn i32_to_i16(arr: *mut i32, size: usize) -> i32 { impl_i16be!(i32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn i32_to_i32(arr: *mut i32, size: usize) -> i32 { impl_i32be!(i32, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn u16_to_i16(arr: *mut u16, size: usize) -> u16 { impl_i16be!(u16, arr, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn i16_to_i16(arr: *mut i16, size: usize) -> i16 { impl_i16be!(i16, arr, size) } diff --git a/src/library.rs b/src/library.rs index 15ae3c8..bf4c890 100644 --- a/src/library.rs +++ b/src/library.rs @@ -64,7 +64,7 @@ impl FileHeader { /// Returns: /// FileHeader object /// - pub fn read(input: &[u8]) -> IResult { + pub fn read(input: &[u8]) -> IResult<'_, Self> { let (input, _version) = records::HEADER::read(input)?; let (input, [mod_time, acc_time]) = records::BGNLIB::read(input)?; let (input, name) = records::LIBNAME::skip_and_read(input)?; @@ -98,7 +98,7 @@ impl FileHeader { } -pub fn read_library(input: &[u8]) -> IResult { +pub fn read_library(input: &[u8]) -> IResult<'_, StructArray> { let input_size = input.len(); let property_t = DataType::Struct(Fields::from(vec![ diff --git a/src/record.rs b/src/record.rs index 3226dbb..8bc482c 100644 --- a/src/record.rs +++ b/src/record.rs @@ -24,7 +24,7 @@ pub struct RecordHeader { } impl RecordHeader { - pub fn read(input: &[u8]) -> IResult { + pub fn read(input: &[u8]) -> IResult<'_, RecordHeader> { let (input, size) = parse_u16(input)?; let (input, tag) = parse_u16(input)?; Ok((input, RecordHeader{tag, data_size:size - 4})) @@ -50,7 +50,7 @@ pub trait RecordData { type InData : ?Sized; type ByteData : AsRef<[u8]>; - fn read(input: &[u8], size: u16) -> IResult>; + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>>; fn pack_into(buf: &mut [u8], data: &Self::InData); //fn size(data: &Self::BareData<'_>) -> u16; fn pack(data: &Self::InData) -> Self::ByteData; @@ -72,7 +72,7 @@ pub trait Record { } } - fn read_header(input: &[u8]) -> IResult { + fn read_header(input: &[u8]) -> IResult<'_, RecordHeader> { RecordHeader::read(input) } @@ -80,7 +80,7 @@ pub trait Record { RecordHeader{tag: Self::tag(), data_size}.write(ww) } - fn read_data(input: &[u8], size: u16) -> IResult> { + fn read_data(input: &[u8], size: u16) -> IResult<'_, RData::BareData<'_>> { RData::read(input, size) } @@ -95,7 +95,7 @@ pub trait Record { /// True if the record was encountered and skipped. /// False if the end of the library was reached. /// - fn skip_past(input: &[u8]) -> IResult { + fn skip_past(input: &[u8]) -> IResult<'_, bool> { let original_input = input; let (mut input, mut header) = RecordHeader::read(input)?; while header.tag != Self::tag() { @@ -109,7 +109,7 @@ pub trait Record { Ok((input, true)) } - fn skip_and_read(input: &[u8]) -> IResult> { + fn skip_and_read(input: &[u8]) -> IResult<'_, RData::BareData<'_>> { let (mut input, mut header) = RecordHeader::read(input)?; while header.tag != Self::tag() { (input, _) = take_bytes(input, header.data_size)?; @@ -119,7 +119,7 @@ pub trait Record { Ok((input, data)) } - fn expect_header(input: &[u8]) -> IResult { + fn expect_header(input: &[u8]) -> IResult<'_, u16> { let (input, header) = RecordHeader::read(input)?; if header.tag != Self::tag() { fail(input, format!("Unexpected record! Got tag 0x{:04x}, expected 0x{:04x}", header.tag, Self::tag())) @@ -128,7 +128,7 @@ pub trait Record { } } - fn read(input: &[u8]) -> IResult> { + fn read(input: &[u8]) -> IResult<'_, RData::BareData<'_>> { let (input, size) = Self::expect_header(input)?; Self::check_size(size).unwrap(); let (input, data) = Self::read_data(input, size)?; @@ -152,7 +152,7 @@ impl RecordData for BitArray { type InData = [bool; 16]; type ByteData = [u8; 2]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 2); parse_bitarray(input) } @@ -175,7 +175,7 @@ impl RecordData for Int2 { type InData = i16; type ByteData = [u8; 2]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 2); parse_int2(input) } @@ -197,7 +197,7 @@ impl RecordData for Int4 { type InData = i32; type ByteData = [u8; 4]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 4); parse_int4(input) } @@ -220,7 +220,7 @@ impl RecordData for Int2Array { type InData = [i16]; type ByteData = Vec; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size % 2 == 0, "Record must contain an integer quantity of integers"); //let mut input = input; let (input, bytes) = take_bytes(input, size)?; @@ -261,7 +261,7 @@ impl RecordData for Int4Array { type InData = [i32]; type ByteData = Vec; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size % 4 == 0, "Record must contain an integer quantity of integers"); //let mut input = input; let (input, bytes) = take_bytes(input, size)?; @@ -302,7 +302,7 @@ impl RecordData for Real8 { type InData = f64; type ByteData = [u8; 8]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 8); parse_real8(input) } @@ -324,7 +324,7 @@ impl RecordData for Real8Pair { type InData = (f64, f64); type ByteData = [u8; 2 * 8]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 2 * 8); let (input, data0) = parse_real8(input)?; let (input, data1) = parse_real8(input)?; @@ -354,7 +354,7 @@ impl RecordData for ASCII { type InData = [u8]; type ByteData = Vec; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { parse_ascii(input, size) } @@ -376,7 +376,7 @@ impl RecordData for DateTimePair { type InData = [[i16; 6]; 2]; type ByteData = [u8; 2 * 6 * 2]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 2 * 6 * 2); let (input, data0) = parse_datetime(input)?; let (input, data1) = parse_datetime(input)?; @@ -406,7 +406,7 @@ impl RecordData for Empty { type InData = (); type ByteData = [u8; 0]; - fn read(input: &[u8], size: u16) -> IResult> { + fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> { assert!(size == 0); Ok((input, ())) }