Matcher Rust Implement C FFI bindings
A high-performance matcher designed to solve LOGICAL and TEXT VARIATIONS problems in word matching, implemented in Rust with C FFI bindings for cross-language support.
For detailed implementation, see the Design Document.
Overview
This package provides C FFI (Foreign Function Interface) bindings for the Matcher library. It allows you to use the high-performance matching capabilities of Matcher in C, C++, Python (via cffi), and other languages that support C FFI.
Key features exposed:
- High-performance text matching with logical operators (
&,~). - Support for various text normalization processes (Fanjian, Delete, Normalize, PinYin).
- Multiple matching types: Simple, Regex, Similarity, Acrostic.
Installation
Build from source
git clone https://github.com/Lips7/Matcher.git
cd Matcher/matcher_c
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y
cargo build --release
After building, you will find the dynamic library in the target/release directory:
- Linux:
libmatcher_c.so - macOS:
libmatcher_c.dylib - Windows:
matcher_c.dll
Install pre-built binary
Visit the release page to download the pre-built binary.
C Usage Example
You can use the matcher_c.h header and the compiled library in your C projects.
int
Python Usage Example
Using the C FFI bindings via Python's cffi library and the provided extension_types.py:
# Initialize FFI and load library
=
= # Adjust extension for your OS
# Define configuration using extension types
=
# Init matcher
=
# Check match
=
# Match and get string result
=
# Clean up
Important Notes
- Header File: The
matcher_c.hdefines the exported functions. - Memory Management: Always call
drop_matcher,drop_simple_matcher, anddrop_stringfor any pointer returned by the library to avoid memory leaks. - Extension Types: The extension_types.py helper provides
TypedDictand utility classes to ensure your configuration JSON structure is correct. - Rust Toolchain: Building from source requires the Rust nightly toolchain.