freifunk-saar / ff-node-monitor

Monitoring for Freifunk nodes
GNU Affero General Public License v3.0
3 stars 2 forks source link

Don't send warnings if ALL nodes are offline #69

Closed rubo77 closed 4 years ago

rubo77 commented 4 years ago

I get some errors when compiling .
i did never program Rust so far, but I guess you find my errors immediately ;)

closes #66

rubo77 commented 4 years ago

I fixed all errors but one, that I don't understand:

error[E0382]: borrow of moved value: `cur_nodes_map`
   --> src/cron.rs:157:41
    |
143 |         for (_id, cur_data) in cur_nodes_map.into_iter() {
    |                                ------------- value moved here
...
157 |                 if let Some(cur_data) = cur_nodes_map.remove(&id) {
    |                                         ^^^^^^^^^^^^^ value borrowed here after move
    |
    = note: move occurs because `cur_nodes_map` has type `std::collections::HashMap<std::string::String, cron::NodeData>`, which does not implement the `Copy` trait
RalfJung commented 4 years ago

into_iter consumes cur_nodes_map. Try using iter instead.

rubo77 commented 4 years ago

into_iter consumes cur_nodes_map. Try using iter instead.

BUt the code later uses into_iter also in the same manner. Why would there be the difference needed?

RalfJung commented 4 years ago

BUt the code later uses into_iter also in the same manner. Why would there be the difference needed?

Because the code later is the last time the map is used. After using into_iter, you cannot use the map ever again later. So it's okay for the last iteration, but not before.

See https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html

rubo77 commented 4 years ago

I don't understand this error: https://travis-ci.org/github/freifunk-saar/ff-node-monitor/builds/698531035#L502

RalfJung commented 4 years ago

() has type () but you need to return something of type Result<()>.

Try return Ok(());.

rubo77 commented 4 years ago

Try return Ok(());.

now it compiles well.

I guess, I could also have used just

OK(())

(without semicolon)

RalfJung commented 4 years ago

If the expression is the last in the block, yes. But not here which is in the middle of the body. Early return still needs return in Rust.

RalfJung commented 4 years ago

bors r+

RalfJung commented 4 years ago

bors retry

bors[bot] commented 4 years ago

Already running a review

bors[bot] commented 4 years ago

Build succeeded: