These are chat archives for rust-lang/rust

30th
Jun 2018
Sylwester Rąpała
@xoac
Jun 30 2018 09:58 UTC
Is there a rust way to work more easily with time. For example I have a struct that holds some times. But that times are u16 (I work with embeded devices) and I would like to guarantee that I will never overwrite that value. If sb is familiar with C++ I can achieve that by std::chrono::duration<uint16_t, std::ratio<1>>
Denis Lisov
@tanriol
Jun 30 2018 10:10 UTC
What do you mean by "never overwrite"? Do you want a struct's field to be readonly? What type of problems are you guarding against?
Sylwester Rąpała
@xoac
Jun 30 2018 11:37 UTC
No. I want to be sure I have a proper values in struct.
So for example MyDuration::fom_sec(u16::max_value() + 1) fail
Denis Lisov
@tanriol
Jun 30 2018 11:47 UTC
Well, this is not a question of your structure, but of whether the assertions on overflow are turned on...
Sylwester Rąpała
@xoac
Jun 30 2018 18:50 UTC
can cargo fix applay warnings suggestions?
Sylwester Rąpała
@xoac
Jun 30 2018 18:52 UTC
To get the tool to automatically fix warnings in, run cargo install cargo-fix. This will give you cargo fix.
I did it and names of variable all still not proper
Andrey Lesnikov
@ozkriff
Jun 30 2018 18:54 UTC
nothing has changed at all? you are running cargo fix, right?
Sylwester Rąpała
@xoac
Jun 30 2018 18:54 UTC
yes
Andrey Lesnikov
@ozkriff
Jun 30 2018 18:55 UTC
then open an issue, i guess - https://github.com/rust-lang-nursery/rustfix/issues :(
Fredrik Portström
@portstrom
Jun 30 2018 18:56 UTC
Why do I get videos of old IBM computers running Fortran in the list of related videos whenever I watch a video about Rust on Youtube. :confounded:
Sylwester Rąpała
@xoac
Jun 30 2018 18:57 UTC
@ozkriff
I lie cargo fix just printed me warning like while building:
warning: variable `comm_p_TX_cntr` should have a snake case name such as `comm_p_tx_cntr`
   --> src/data/aggregator.rs:201:13
    |
201 |         let comm_p_TX_cntr = buf.get_u16_le();
    |             ^^^^^^^^^^^^^^

warning: variable `comm_p_RX_cntr` should have a snake case name such as `comm_p_rx_cntr`
   --> src/data/aggregator.rs:202:13
    |
202 |         let comm_p_RX_cntr = buf.get_u16_le();
    |             ^^^^^^^^^^^^^^
but git diff is empty
Andrey Lesnikov
@ozkriff
Jun 30 2018 19:05 UTC
btw, just checked and it works for me with some basic examples:
$ c b
   Compiling testme v0.1.0 (file:///home/ozkriff/zemeroth/testme)
warning: unused variable: `a`
 --> src/main.rs:2:9
  |
2 |     let a = 100;
  |         ^ help: consider using `_a` instead
  |
  = note: #[warn(unused_variables)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
$ c fix
    Checking testme v0.1.0 (file:///home/ozkriff/zemeroth/testme)
      Fixing src/main.rs (1 fix)
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
$ c b 
   Compiling testme v0.1.0 (file:///home/ozkriff/zemeroth/testme)
    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
$ g diff
diff --git a/src/main.rs b/src/main.rs
index c203a30..393d3cb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
 fn main() {
-    let a = 100;
+    let _a = 100;
     println!("Hello, world!");
 }
$ c fix -V
cargo-fix 0.4.1
Sylwester Rąpała
@xoac
Jun 30 2018 19:06 UTC
should this works also for libs?
Andrey Lesnikov
@ozkriff
Jun 30 2018 19:07 UTC
But rustfix doesn't help with "should have a snake case name such as" error for me too. I gues it's because it doesn't have help: consider ... message
Sylwester Rąpała
@xoac
Jun 30 2018 19:52 UTC
Ok vim has nice visual mode + u to lower :)
Now I have a strange error that I don't understand:
error[E0596]: cannot borrow immutable argument `buf` as mutable
   --> src/data/aggregator.rs:197:54
    |
196 |     pub fn from_buf_le(buf: &mut impl Buf) -> McR0MemMap {
    |                        --- consider changing this to `mut buf`
197 |         let term_state = TermState::from_buf_le(&mut buf);
    |                                                      ^^^ cannot borrow mutably
Andrey Lesnikov
@ozkriff
Jun 30 2018 19:59 UTC
do you really need a reference to a reference? maybe you need just TermState::from_buf_le(buf);?
what is the signature of from_buf_le?
Sylwester Rąpała
@xoac
Jun 30 2018 20:00 UTC
the same as above
thx that works
but it also worked with sugestion from comiler. But I didn't understand that.
Andrey Lesnikov
@ozkriff
Jun 30 2018 20:05 UTC
i think it worked because of the autoderefs - https://doc.rust-lang.org/book/first-edition/deref-coercions.html