Expand description
Safe Rust bindings for libnfc built on top of [nfc-sys].
The ffi module re-exports the raw nfc-sys API for advanced use cases.
The top-level API in this crate focuses on ownership, resource cleanup, and
slice-based wrappers for the parts of libnfc that can be expressed safely.
Some libnfc capabilities remain raw-only because the C API itself requires
unchecked callbacks or driver pointers. In particular, custom driver
registration and target emulation state machines still live in ffi.
§Native Dependency
This crate links against a system installation of libnfc. You must install
the native library before building or running code that depends on nfc.
The underlying nfc-sys build script handles the actual linking step.
Common setups:
- macOS:
brew install libnfc - Debian/Ubuntu: install the
libnfcdevelopment package - Custom installs: configure your linker environment as needed for
libnfc
If you need a libnfc capability that is not exposed through the safe API,
use ffi directly and keep the native library installed as above.
§Example
use nfc::{version, Context};
fn main() -> nfc::Result<()> {
let context = Context::new()?;
println!("libnfc version: {}", version());
for connstring in context.list_devices(8)? {
println!("found device: {connstring}");
}
Ok(())
}Re-exports§
Modules§
Structs§
- Context
- Owns a libnfc context and releases it with
nfc_exiton drop. - Device
- Owns an open NFC device and closes it with
nfc_closeon drop. - Timed
Response - Result of a timed transceive operation.
Functions§
- append_
iso14443a_ crc - Appends an ISO14443-A CRC to the provided buffer.
- append_
iso14443b_ crc - Appends an ISO14443-B CRC to the provided buffer.
- baud_
rate_ name - Converts a baud rate to the corresponding libnfc display string.
- iso14443a_
crc - Computes the ISO14443-A CRC for the provided data.
- iso14443b_
crc - Computes the ISO14443-B CRC for the provided data.
- locate_
iso14443a_ historical_ bytes - Locates the ISO14443-A historical bytes inside an ATS buffer.
- modulation_
type_ name - Converts a modulation type to the corresponding libnfc display string.
- target_
to_ string - Formats an NFC target using libnfc’s built-in target formatter.
- version
- Returns the linked libnfc version string as UTF-8.
- version_
cstr - Returns the linked libnfc version string.