kevinmehall / rust-usb

Common definitions for USB constants.
BSD Zero Clause License
24 stars 7 forks source link

use of undeclared trait name `std::num::FromPrimitive` #16

Closed djanderson closed 9 years ago

djanderson commented 9 years ago
$ rustc --version
rustc 1.0.0-beta.4 (built 2015-05-07)

Trying to compile the first part of your example here: https://github.com/kevinmehall/rust-usb/blob/master/examples/test/main.rs

extern crate usb;
use usb::libusb;

fn main() {
    let c = usb::Context::new();
    c.set_debug(2);

    let devices = c.list_devices();

    for dev in devices.iter() {
        let desc = dev.descriptor();
        println!("Device {:03}.{:03} {:04x}:{:04x}",
                 dev.bus(),
                 dev.address(),
                 desc.idVendor,
                 desc.idProduct  );
    }
}
$ cat Cargo.lock 
[root]
name =
version = "0.1.0"
dependencies = [
 "usb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "usb"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
$ cargo build --verbose
   Compiling usb v0.2.1
     Running `rustc ~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/usb.rs --crate-name usb --crate-type lib -g -C metadata=6d2d6d7f7ed71c6f -C extra-filename=-6d2d6d7f7ed71c6f --out-dir ~/dev/rust/rustl-sdr/target/debug/deps --emit=dep-info,link -L dependency=~/dev/rust/target/debug/deps -L dependency=~/dev/rust/target/debug/deps -Awarnings`
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:492:23: 492:36 error: use of undeclared trait name `std::num::FromPrimitive`
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:492 #[derive(Copy, Clone, FromPrimitive, Debug, PartialEq, Eq)]
                                                                                                              ^~~~~~~~~~~~~
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:492:23: 492:36 note: in expansion of #[derive_FromPrimitive]
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:492:23: 492:36 note: expansion site
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:601:3: 601:31 error: failed to resolve. Could not find `FromPrimitive` in `std::num`
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:601       num::FromPrimitive::from_u32(self.status).unwrap()
                                                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:601:3: 601:31 error: unresolved name `num::FromPrimitive::from_u32`
~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/libusb.rs:601       num::FromPrimitive::from_u32(self.status).unwrap()
                                                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Could not compile `usb`.

Caused by:
  Process didn't exit successfully: `rustc ~/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-0.2.1/src/usb.rs --crate-name usb --crate-type lib -g -C metadata=6d2d6d7f7ed71c6f -C extra-filename=-6d2d6d7f7ed71c6f --out-dir ~/dev/rust/target/debug/deps --emit=dep-info,link -L dependency=~/dev/rust/target/debug/deps -L dependency=~/dev/rust/target/debug/deps -Awarnings` (exit code: 101)
kevinmehall commented 9 years ago

Fix released in 0.2.2.

The example uses scoped threads, which are an unstable feature, so it will only work on Nightly builds of Rust, but the library itself will work on 1.0 stable and betas as long as you don't need to access a USB device from multiple threads.