These are chat archives for rust-lang/rust

16th
Oct 2017
Sebastian Blei
@iamsebastian
Oct 16 2017 09:39
Got functions used as tests must have signature fn() -> () at one of my hundreds of tests. Dunno how to fix this. Anybody could help?
error: functions used as tests must have signature fn() -> ()
  --> tests/calculation_pk_gs.rs:55:1
   |
55 | / fn test_precalc_ability_to_save(preset_id: i32) -> () {
56 | |     let preset = PresetPkGs::get_one_or_first(Some(99_999_996), None).unwrap();
57 | |     let len = precalc_ability_to_save(preset.id);
58 | |     assert!(len > 0);
59 | | }
   | |_^
Ah, ok. Got it. Grml.
Did not seen, there are arguments in methods definition. Always had just a look at the return type.
Fra ns
@snarf95_twitter
Oct 16 2017 11:52
can rust be used without borrow-checker ?
Aleksey Kladov
@matklad
Oct 16 2017 11:53
In theory, you can use raw pointers instead of references everywhere and put all code in and usafe block.
TatriX
@TatriX
Oct 16 2017 12:26
I'm writing a simple game. It has 2 stages: menu and gameplay itself. I have a main state, which has a Box<Stage> with a current stage.
Then gameplay stage has a button, and I want to change the current stage when the button is clicked. What is the rust way to solve this problem? I'm trying to use a closure passed from the main state to the underlying stage, but it give me scary errors like cannot infer an appropriate lifetime due to conflicting requirements
Pete Hayes
@petehayes102
Oct 16 2017 15:06
Hey guys, quick q - I am getting a trait object from one fn and want to pass it to another. However I am getting the error <type> does not have a constant size known at compile-time. It’s boxed though so I’m confused. Is there any way to do this?
Steve Klabnik
@steveklabnik
Oct 16 2017 15:06
can you share some code?
Pete Hayes
@petehayes102
Oct 16 2017 15:07
I was hoping you wouldn’t ask! I’ll try and knock up a MPV
Gimme a min!
Argh…so my MPV works, which means it’s something stupid in my code. Might need to take a rain check on the help. Thanks anyway!
Steve Klabnik
@steveklabnik
Oct 16 2017 15:10
maybe the compiler output is enough?
like whats the full error
Pete Hayes
@petehayes102
Oct 16 2017 15:12
Ok, here it is:
error[E0277]: the trait bound `intecture_api::prelude::CommandProvider<intecture_api::prelude::Plain>: std::marker::Sized` is not satisfied
  --> src/main.rs:24:21
   |
24 |             let c = Command::new(g, "", None);
   |                     ^^^^^^^^^^^^ `intecture_api::prelude::CommandProvider<intecture_api::prelude::Plain>` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `intecture_api::prelude::CommandProvider<intecture_api::prelude::Plain>`
   = note: required by `<intecture_api::command::Command<H>>::new`

error: aborting due to previous error

error: Could not compile `moo`.
Steve Klabnik
@steveklabnik
Oct 16 2017 15:13
what's the definition of g?
Pete Hayes
@petehayes102
Oct 16 2017 15:14
So g = Box<CommandProvider<Self>>, which comes from a Host trait, which in turn is implemented by a few different host types, i.e. Plain
Steve Klabnik
@steveklabnik
Oct 16 2017 15:14
hmmmm. here it says it's only a CommandProvider
Pete Hayes
@petehayes102
Oct 16 2017 15:15
I know…confusing. Here’s the return signature for the fn it’s wrapping: Box<Future<Item = Box<CommandProvider<H>>, Error = Error>> where H: Host
I’m stuck in dynamic dispatch hell :(
Steve Klabnik
@steveklabnik
Oct 16 2017 15:16
<3
yeah, it's not clear to me. sorry :/
must be something off from your reproduction
since that works
Pete Hayes
@petehayes102
Oct 16 2017 15:17
Ok, well thanks anyway mate. I’ll cry myself to sleep again tonight :D
Ryan
@rnleach
Oct 16 2017 15:36
How can I use the modules of my program from within the build scrip? And where is there good documentation on build.rs files?
Aleksey Kladov
@matklad
Oct 16 2017 15:41
@rnleach docs are here: http://doc.crates.io/build-script.html
You can't depend on modules of your program directly in theory, because your program is build after build.rs is run.
Ryan
@rnleach
Oct 16 2017 15:42
Hmm, I had found those but was hoping there was more.
Aleksey Kladov
@matklad
Oct 16 2017 15:42
However, you can extract common code into a separate crate and depend on it from both your program and bulid.rs
Another, hackish, solution would be to use #[path="/foo/bar/baz.rs"] mod baz; attribute.
Ryan
@rnleach
Oct 16 2017 15:43
Ok, that's what I was looking for. I wanted to read a module and precompute some frequently used values, and place them in a generated source file. The inlclude that file in my program.
Maybe I should just use lazy static
Zakarum
@omni-viral
Oct 16 2017 16:15
Why crates add their own older version as dependency?
Aleksey Kladov
@matklad
Oct 16 2017 18:53
It's called dtolnay's trick: https://github.com/dtolnay/semver-trick