Skip to content

Commit

Permalink
minor updates for libpostal, update deps, fix updated clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pnordahl committed Sep 26, 2023
1 parent 358a4b2 commit 90fc4d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,7 +39,7 @@ impl ExpandAddressOptions {
let c_langs: Vec<CString> = 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);
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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)),
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90fc4d4

Please sign in to comment.