11 releases
0.5.2 | Apr 27, 2023 |
---|---|
0.5.1 | Mar 8, 2023 |
0.5.0 | Dec 7, 2022 |
0.4.1 | Aug 8, 2022 |
0.2.0 | May 2, 2021 |
34 downloads per month
Used in 4 crates
(3 directly)
52KB
1.5K
SLoC
nfc1
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 the it is not guaranteed to succeed - Enums for well-known constants
Result<T, Error>
for methods which can fail- Everything
nfc1-sys
provides, whichnfc-sys
does not- Some internal methods exposed (such as
pn53x_*
, which are useful for accessing manufacturer-specific features in NFC devices)
- Some internal methods exposed (such as
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(())
}
Dependencies
~0.9–3MB
~64K SLoC