These are chat archives for rust-lang/rust

5th
Sep 2018
Andy Hayden
@hayd
Sep 05 2018 03:51
Is there a clean way to read nbytes from stdin? read_exact suggests it throws an error if there's an unexpected EOF (rather than returning Result(uint) it returns Result(()). e.g. using https://stackoverflow.com/a/46225116/1240268
Paul Reesman
@reesmanp
Sep 05 2018 04:50

I keep getting an value moved error. I have a struct that has a u32 and a String property. This struct has a getter for each property. In another function I have this struct and I am remapping its contents and I get this error. Below is an example of what I am doing:

struct MyStruct {
  a: u32,
  b: String
}
...
impl MyStruct {
  fn get_a(self) -> u32 {
    self.a
  }
  fn get_b(self) -> String {
    self.b
  }
  ...
}

struct NewStruct {
  a: u32,
  b: String
}

impl NewStruct {
  fn new(my_struct: MyStruct) -> Self {
    Self {
      a: my_struct.get_a(), // <-- says value was moved here
      b: my_struct.get_b() // <-- says value used after move here
    }
  }
}

What am I doing wrong?

Ryan
@rnleach
Sep 05 2018 05:00
Have the get_a and get_b functions take &self
@reesmanp ^
The method call get_a() takes self by value, so the whole struct gets moved into the struct.
Since u32 is a copy type, you won't have to worry about returning it. However, String is not a copy type, so you'll need to clone it on return.
Ryan
@rnleach
Sep 05 2018 05:06
If both structs are defined in the same file, you could use the variables directly without the need for method calls.
Paul Reesman
@reesmanp
Sep 05 2018 05:09
@rnleach they aren't :( but your suggestion worked. I thought I tried &self by itself but must not have I think I tried (&self) -> &self which would require a change on the callee end.
Thanks.
Tom Cumming
@tomcumming
Sep 05 2018 08:50
Is anyone in here using wasm bindgen ?
I am having trouble using it with parcel-bundler
wasm-bindgen emits import statements for wasm modules without the .wasm extension and i dont think parcel is trying to resolve them
(this works fine in webpack, i can just add the .wasm extension to my resolve config)
David Sinclair
@dsincl12
Sep 05 2018 09:31
hi everyone
need to use cargo clippy in a new development environment. followed the instructions in clippy's README.md but after doing rustup component add clippy-preview --toolchain=nightly I still get no such subcommand: clippy when trying to run cargo clippy.
cargo +nightly clippy gives the same results (nightly is the only toolchain on this system)
rustup component list includes clippy-preview-x86_64-apple-darwin (installed)
Lyle Mantooth
@IslandUsurper
Sep 05 2018 12:46

@xoac, I think the easiest thing to do here is impl Default for MyStruct yourself (not deriving it). Unless you mean the only valid values that go in a are 0 through 64. Then I'd probably make a an array of enums with repr(u32).

Hi, I would like to deserialize a struct struct MyStruct { a: [u32; 64] } And I want a can be filled from 0 to 64 and the rest is filled with Default::default

Sylwester Rąpała
@xoac
Sep 05 2018 13:10
@IslandUsurper I would like to de-serialize that struct from for example json: I have a json "MyStruct": [5, 4, 3] and that should deserialize to my struct
Lyle Mantooth
@IslandUsurper
Sep 05 2018 13:11
Oh, I see. a would then have the 5, 4, 3 and a bunch of 0s to fill out the array.
Have you tried it? Derive Default on MyStruct, and set the serde attribute to default and see if it gives you an error.
Sylwester Rąpała
@xoac
Sep 05 2018 13:32
@IslandUsurper I don't understand de-serialization quite well at the moment.. So I think it's a problem
Lyle Mantooth
@IslandUsurper
Sep 05 2018 13:36
But have you tried it, @xoac? Unless you know for sure it doesn't work, and Serde gives you an error message, then you don't know it's a problem.
Sylwester Rąpała
@xoac
Sep 05 2018 14:23
I have tried to write own deserialize funtion. (And it didn't work). I will try it tomorrow once again. Today I am busy with other emergency stuff
Lyle Mantooth
@IslandUsurper
Sep 05 2018 14:36
@xoac, I don't mean write your own deserializer. I mean use the automatic tools serde already gives you. Try deriving Default and Deserialize and see what it does without you having to work a whole bunch.
Sylwester Rąpała
@xoac
Sep 05 2018 16:13
@IslandUsurper the problem is that there is [sth; 64] Fixed arrays are only defined to 32
   |                       ^^^^^^^^^ the trait `serde::Serialize` is not implemented for `[events::slots::Slot; 64]`
Zakarum
@omni-viral
Sep 05 2018 18:00
@xoac use #[serde(deserialize_with = "path")] attribute
David Blewett
@davidblewett
Sep 05 2018 21:40
has anyone tried to get rustls talking to a puma server (ruby application server)? No matter what I do, I end up with #<Puma::MiniSSL::SSLError: OpenSSL error: error:1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher - 336109761> from puma.
the native-tls crate is able to (presumably because of less strict requirements?)