ewilken / hap-rs

Rust implementation of the Apple HomeKit Accessory Protocol (HAP)
Apache License 2.0
197 stars 35 forks source link

Rustling issue with the examples #29

Closed anoldguy closed 4 years ago

anoldguy commented 4 years ago

Hey all! I am a rust beginner. I've been thru rustlings, and feel like I've got a small bit figured out. So, of course, one then jumps into the deep end.

I don't understand how the examples are supposed to work. I've setup a new project, and listed hap = "0.0.10" in my cargo.toml, but when I try to use one of the examples as my main program, it fails to compile at all. (Example in question: https://github.com/ewilken/hap-rs/blob/master/examples/lightbulb.rs)

➜ cargo build
   Compiling virtual_hap v0.1.0 (/home/anoldguy/code/virtual_hap)
error[E0432]: unresolved imports `hap::accessory::lightbulb::LightbulbAccessory`, `hap::accessory::AccessoryCategory`, `hap::server`, `hap::storage`, `hap::tokio`, `hap::MacAddress`, `hap::Pin`
  --> src/main.rs:4:17
   |
4  |     accessory::{lightbulb::LightbulbAccessory, AccessoryCategory, AccessoryInformation},
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^ no `AccessoryCategory` in `accessory`
   |                 |
   |                 no `LightbulbAccessory` in `accessory::lightbulb`
5  |     server::{IpServer, Server},
   |     ^^^^^^ could not find `server` in `hap`
6  |     storage::{FileStorage, Storage},
   |     ^^^^^^^ could not find `storage` in `hap`
7  |     tokio,
   |     ^^^^^ no `tokio` in the root
8  |     Config,
9  |     MacAddress,
   |     ^^^^^^^^^^ no `MacAddress` in the root
10 |     Pin,
   |     ^^^
   |     |
   |     no `Pin` in the root
   |     help: a similar name exists in the module: `pin`

error[E0433]: failed to resolve: use of undeclared type or module `pnet`
  --> src/main.rs:16:22
   |
16 |         for iface in pnet::datalink::interfaces() {
   |                      ^^^^ use of undeclared type or module `pnet`

error[E0433]: failed to resolve: use of undeclared type or module `env_logger`
  --> src/main.rs:59:5
   |
59 |     env_logger::init();
   |     ^^^^^^^^^^ use of undeclared type or module `env_logger`

error[E0603]: type alias `AccessoryInformation` is private
 --> src/main.rs:4:67
  |
4 |     accessory::{lightbulb::LightbulbAccessory, AccessoryCategory, AccessoryInformation},
  |                                                                   ^^^^^^^^^^^^^^^^^^^^ private type alias
  |
note: the type alias `AccessoryInformation` is defined here
 --> /home/anoldguy/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.10/src/accessory/mod.rs:8:39
  |
8 |         accessory_information::{self, AccessoryInformation},
  |                                       ^^^^^^^^^^^^^^^^^^^^

error[E0560]: struct `hap::config::Config` has no field named `socket_addr`
  --> src/main.rs:41:17
   |
41 |                 socket_addr: SocketAddr::new(current_ipv4().unwrap(), 32000),
   |                 ^^^^^^^^^^^ `hap::config::Config` does not have this field
   |
   = note: available fields are: `storage_path`, `ip`, `port`, `pin`, `name` ... and 10 others

error[E0277]: `main` has invalid return type `impl std::future::Future`
  --> src/main.rs:14:17
   |
14 | async fn main() {
   |                 ^ `main` can only return types that implement `std::process::Termination`
   |
   = help: consider using `()`, or a `Result`

error[E0752]: `main` function is not allowed to be `async`
  --> src/main.rs:14:1
   |
14 | async fn main() {
   | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0277, E0432, E0433, E0560, E0603, E0752.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `virtual_hap`.

I clearly need to understand more of rust's basics before diving in, but I don't even know where to start. For example, the last error error[E0752]:mainfunction is not allowed to beasync`` indicates that I'm supposed to be calling these from some larger parent program, I think?

Are these examples supposed to run out of the box? My goal was to expose a virtual garage door so I could test some logic, but I'm completely out of my depth here.

I also realize this isn't your issue, but maybe just a plea to include a full example somewhere to help make things easier for folks new to rust?

Feel free to close this if it's not inline with your project goals or time constraints!

Roba1993 commented 4 years ago

@anoldguy The version 0.10 is still based upon a sync connection and has a different API. If you want to get that, run cargo doc locally.

From my expirence with the crate. better try the actual async version which is only available in master of git. Check the docu here if you don't know how this works.

Thanks, Robert

ewilken commented 4 years ago

Hi! Thanks for caring and sorry for the unresponsiveness lately!

As @Roba1993 said correctly, the master branch of this repo differs from the old version currently published on crates.io, and there are still a few TODOs left on this rewrite, like updating the docs properly and solving some issues like the one mentioned here in #28. But to prevent future confusion of people finding this repo, I should probably publish the master branch as a v0.1.0-pre.1 to crates.io now. Will do that.

I'm also trying to add extensive examples to this repo and to the docs. The ones in the examples directory should all already work with the master branch.

For the time being, I'm trying to track my progress with the rewrite in this project. And of course, contributions in the form of issues & PRs are always very welcome! :)

anoldguy commented 4 years ago

Thank you @Roba1993! I'll look into that. Like I said, I'm a complete newbie at rust, so lots of learning still. Thanks for your patience with me!

@ewilken, thanks so much for this software. I'm really looking forward to getting things working! Since things are in flux a ton still, I'll go ahead and close this issue and keep an eye on the repo manually.