From 6d4a7f5263a41ae7a7ada7c473874aed01062d1c Mon Sep 17 00:00:00 2001 From: Patrick Nordahl Date: Tue, 26 Sep 2023 07:59:58 -0500 Subject: [PATCH] minor updates for libpostal, update deps, fix updated clippy errors (#11) --- Cargo.toml | 6 +++--- README.md | 5 +++++ build.rs | 2 +- src/lib.rs | 16 ++++++---------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e690af9..d5257d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "FFI bindings and safe interface to libpostal" license = "MIT" homepage = "https://github.com/pnordahl/rust-postal" repository = "https://github.com/pnordahl/rust-postal" -version = "0.2.5" +version = "0.2.6" authors = ["Patrick Nordahl "] edition = "2021" build = "build.rs" @@ -16,10 +16,10 @@ keywords = ["libpostal", "postal", "addresses"] criterion = "0.2" [dependencies] -parking_lot = "0.8.0" +parking_lot = "0.12.0" [build-dependencies] -bindgen = "0.60" +bindgen = "0.68" [[bench]] name = "benches" diff --git a/README.md b/README.md index 0712606..764588c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ This library provides [rust-lang/rust-bindgen](https://github.com/rust-lang/rust-bindgen) generated Rust <-> C bindings, and puts an ergonomic and safe Rust API on top of them. +This crate requires Rust 1.60 or newer. + ## Installation Follow the README instructions at [openvenues/libpostal](https://github.com/openvenues/libpostal) to install the shared library for your platform. Currently, the compiled object is dynamically linked when your project runs - static linkage could be supported in the future. @@ -95,6 +97,9 @@ cargo bench Note: `--test-threads 1` is required due to the single-threaded nature of `libpostal`. ## Release History +* 0.2.6 + * Update bindgen and parking_lot, replace deprecated rustfmt_bindings with formatter for bindgen + * 0.2.2 * Resolve locking issue due to unbound Mutex guard. diff --git a/build.rs b/build.rs index 130c192..62e8909 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,7 @@ fn main() { println!("cargo:rustc-link-lib=dylib=postal"); let bindings = bindgen::Builder::default() - .rustfmt_bindings(true) + .formatter(bindgen::Formatter::Rustfmt) .header("wrapper.h") .derive_debug(true) .trust_clang_mangling(false) diff --git a/src/lib.rs b/src/lib.rs index b084e45..34572fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,14 +5,13 @@ extern crate parking_lot; -#[allow(clippy::too_many_arguments)] +#[allow(clippy::all)] mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } pub use bindings::*; use parking_lot::Mutex; -use std::convert::TryInto; use std::error; use std::ffi::{CStr, CString}; use std::fmt; @@ -40,7 +39,7 @@ impl ExpandAddressOptions { let c_langs: Vec = langs.iter().map(|l| CString::new(*l).unwrap()).collect(); let mut ptrs: Vec<*const c_char> = c_langs.iter().map(|cs| cs.as_ptr()).collect(); self.opts.languages = ptrs.as_mut_ptr() as *mut *mut c_char; - self.opts.num_languages = ptrs.len() as u64; + self.opts.num_languages = ptrs.len(); self.c_languages = Some(c_langs); self.c_languages_ptrs = Some(ptrs); } @@ -95,10 +94,7 @@ impl<'a> Iterator for Expansions<'a> { impl<'a> Drop for Expansions<'a> { fn drop(&mut self) { unsafe { - libpostal_expansion_array_destroy( - self.array, - (self.array_length as usize).try_into().unwrap(), - ); + libpostal_expansion_array_destroy(self.array, self.array_length as usize); } } } @@ -249,9 +245,9 @@ impl Context { Ok(c_string) => { let addr = c_string.as_ptr() as *mut c_char; - let mut num_expansions: u64 = 0; + let mut num_expansions: usize = 0; let raw = libpostal_expand_address(addr, opts.opts, &mut num_expansions); - Ok(Expansions::new(raw, num_expansions.try_into().unwrap())) + Ok(Expansions::new(raw, num_expansions)) } Err(e) => Err(PostalError::BadCString(e)), } @@ -324,7 +320,7 @@ impl fmt::Display for PostalError { } PostalError::LibpostalEnableParsing => write!(f, "libpostal_setup_parser failed"), PostalError::BadCString(ref err) => { - write!(f, "failed to convert &str into c string, error: '{}'", err) + write!(f, "failed to convert &str into c string, error: '{err}'") } PostalError::LibpostalNotReady => write!( f,