Git Product home page Git Product logo

rs-nfc1's Introduction

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 the 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
    • Some internal methods exposed (such as pn53x_*, which are useful for accessing manufacturer-specific features in NFC devices)

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(())
}

rs-nfc1's People

Contributors

alexrsagen avatar xanderio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

moogle19

rs-nfc1's Issues

Could not compile `nfc1`: no `size_t` in the root

As the title states, I can't compile the module using:

Darwin riklus-macbookpro.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Jun 21 20:50:28 PDT 2022; root:xnu-7195.141.32~1/RELEASE_X86_64 x86_64
cargo 1.67.1 (8ecd4f20a 2023-01-10)
rustc 1.67.1 (d5a82bbd2 2023-02-07)

  1. Clone the repo
  2. Run cargo check
    Updating crates.io index
   Compiling libc v0.2.139
   Compiling memchr v2.5.0
   Compiling glob v0.3.1
   Compiling cfg-if v1.0.0
   Compiling proc-macro2 v1.0.51
   Compiling unicode-ident v1.0.6
   Compiling log v0.4.17
   Compiling quote v1.0.23
   Compiling clang-sys v1.4.0
   Compiling aho-corasick v0.7.20
   Compiling regex-syntax v0.6.28
   Compiling version_check v0.9.4
   Compiling cc v1.0.79
   Compiling nom v5.1.2
   Compiling libloading v0.7.4
   Compiling bitflags v1.3.2
   Compiling pkg-config v0.3.26
   Compiling regex v1.7.1
   Compiling atty v0.2.14
   Compiling rustc-hash v1.1.0
   Compiling unicode-width v0.1.10
   Compiling lazy_static v1.4.0
   Compiling peeking_take_while v0.1.2
   Compiling shlex v1.1.0
   Compiling lazycell v1.3.0
   Compiling textwrap v0.11.0
   Compiling termcolor v1.2.0
   Compiling humantime v2.1.0
   Compiling vec_map v0.8.2
   Compiling bindgen v0.58.1
   Compiling ansi_term v0.12.1
   Compiling strsim v0.8.0
   Compiling cexpr v0.4.0
   Compiling clap v2.34.0
   Compiling env_logger v0.8.4
   Compiling libusb1-sys v0.5.0
   Compiling which v3.1.1
   Compiling minimal-lexical v0.2.1
   Compiling syn v1.0.107
   Compiling nom v7.1.3
   Compiling either v1.8.1
   Compiling bindgen v0.63.0
   Compiling which v4.4.0
   Compiling cexpr v0.6.0
   Compiling cmake v0.1.49
   Compiling usb-compat-01-sys v0.2.3
   Compiling nfc1-sys v0.3.1
    Checking nfc1 v0.5.0 (/Users/username/rs-nfc1)
error[E0432]: unresolved import `nfc1_sys::size_t`
 --> src/lib.rs:2:2
  |
2 |     size_t,
  |     ^^^^^^ no `size_t` in the root

error[E0432]: unresolved import `nfc1_sys::size_t`
 --> src/target/info.rs:2:5
  |
2 | use nfc1_sys::size_t;
  |     ^^^^^^^^^^^^^^^^ no `size_t` in the root
  |
help: consider importing this unresolved item instead
  |
2 | use crate::size_t;
  |     ~~~~~~~~~~~~~~

error[E0432]: unresolved import `nfc1_sys::size_t`
 --> src/context.rs:2:16
  |
2 | use nfc1_sys::{size_t, nfc_context, nfc_connstring, nfc_init, nfc_exit, nfc_list_devices};
  |                ^^^^^^ no `size_t` in the root
  |
help: consider importing this unresolved item instead
  |
2 | use nfc1_sys::{crate::size_t;
  |                ~~~~~~~~~~~~~~

error[E0432]: unresolved import `nfc1_sys::size_t`
  --> src/device.rs:18:2
   |
18 |     size_t,
   |     ^^^^^^ no `size_t` in the root
   |
help: consider importing this unresolved item instead
   |
18 |     crate::size_t;
   |

For more information about this error, try `rustc --explain E0432`.
error: could not compile `nfc1` due to 4 previous errors

Build failed when used as dependency with default-features = false

I added nfc1 as a dependency with:

$ cargo add nfc1 --no-default-features   

Then ran the script.

$ cargo run
    Blocking waiting for file lock on build directory
   Compiling nfc1-sys v0.3.4
   Compiling nfc1 v0.5.1
error[E0432]: unresolved imports `nfc1_sys::pn53x_transceive`, `nfc1_sys::pn53x_read_register`, `nfc1_sys::pn53x_write_register`
  --> /Users/username/.cargo/registry/src/github.com-1ecc6299db9ec823/nfc1-0.5.1/src/device.rs:23:2
   |
23 |     pn53x_transceive,
   |     ^^^^^^^^^^^^^^^^ no `pn53x_transceive` in the root
24 |     pn53x_read_register,
   |     ^^^^^^^^^^^^^^^^^^^ no `pn53x_read_register` in the root
25 |     pn53x_write_register,
   |     ^^^^^^^^^^^^^^^^^^^^ no `pn53x_write_register` in the root

For more information about this error, try `rustc --explain E0432`.
error: could not compile `nfc1` due to previous error

It's referencing these lines:

rs-nfc1/src/device.rs

Lines 23 to 25 in 258ae6a

pn53x_transceive,
pn53x_read_register,
pn53x_write_register,

Probable cause

This is likely because when the default features are disabled, the default drivers in nfc1-sys are being disabled too:

https://github.com/alexrsagen/rs-nfc1-sys/blob/a8e2c8a999ca71e93c7af9e098218bc85717b219/Cargo.toml#L26-L32

Thereforebuild.rs does not genereates the bindings for the drivers.

Possible fix

When the --no-default-features flag is used the pn53x_* functions should not be included.

I suggest excluding these imports when the --no-default-features flag is enabled:

https://github.com/alexrsagen/rs-nfc1-sys/blob/a8e2c8a999ca71e93c7af9e098218bc85717b219/Cargo.toml#L26-L32

TargetInfo struct fields non public

All fields of all structs which are used in the TargetInfo enum are non pub this makes it impossible to access e.g. the uid of a target. Is this an over side or indented?ri

Rustfmt

This project is not formatted with rustfmt, or it is but to config is not included in the repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.