nfc1

Crates.ionfc1
lib.rsnfc1
version0.6.1
created_at2021-05-02 16:54:28.639195+00
updated_at2026-01-03 04:00:36.228657+00
descriptionHigh-level safe Rust bindings for libnfc.
homepage
repositoryhttps://github.com/alexrsagen/rs-nfc1
max_upload_size
id392230
size68,944
Alexander Sagen (alexrsagen)

documentation

README

nfc1

Crates.io

High-level safe Rust bindings for libnfc.

This crate provides a safe wrapper around nfc1-sys.

In contrast to nfc, this crate additionally provides:

  • Extra safety
    • No exposed raw pointers
    • No .unwrap() where it is not guaranteed to succeed
    • Enums for well-known constants
  • Result<T, Error> for methods which can fail
  • Everything nfc1-sys provides, which nfc-sys does not
    • Access to internal methods (such as pn53x_*), which are useful for accessing manufacturer-specific features in NFC devices
    • Vendored submodule copy of libnfc (with build tweaks for x86_64-pc-windows-msvc), which means you don't have to separately install libnfc to use this crate. The vendoring is optional and can be disabled by removing the vendored feature.

Usage

Add nfc1 as a dependency in your project's Cargo.toml file:

[dependencies]
nfc1 = "0.5"

Import the nfc1 crate in your project, then you can use all the wrapped functions from libnfc.

See the libnfc wiki or libnfc 1.8.0 examples for information on how to use libnfc.

Usage example

fn main() -> nfc1::Result<()> {
	println!("libnfc v{}", nfc1::version());

	let mut context = nfc1::Context::new()?;
	let mut device = context.open()?;

	println!("NFC device {:?} opened through connection {:?}", device.name(), device.connstring());
	println!("- Initiator modulations: {:?}", device.get_supported_modulation(nfc1::Mode::Initiator)?);
	println!("- Target modulations: {:?}", device.get_supported_modulation(nfc1::Mode::Target)?);

	Ok(())
}
Commit count: 27

cargo fmt