These are chat archives for rust-lang/rust

3rd
Mar 2019
Naja Melan
@najamelan
Mar 03 07:47
how do I take an async function as a parameter? This does not work: where F: Fn( Request<Body> ) -> impl futures::Future< Output = Result< Response<Body>, hyper::Error > >
william.hng
@wilhg
Mar 03 10:47

try it out

let newuser: User = User {
    name: "string".to_string(),
    age: 0,
}

@erduranogulcan

william.hng
@wilhg
Mar 03 10:54
misunderstood... sorry
Ogulcan Erduran
@erduranogulcan
Mar 03 10:54
@wilhg thanks for your interest
Tim Robinson
@1tgr
Mar 03 11:31
Are you sure that's supported in VS Code/Racer/RLS?
They're different from the Intellij plugin, I think the plugin can do more stuff
octave99
@octave99
Mar 03 14:06
Is there a better way to achieve below:
fn main() {
    let mut parent = vec![1, 2, 3, 4, 5];
    let child = [10, 20, 30];
    parent.splice(..child.len(), child.iter().cloned());
    assert_eq!(parent, [10, 20, 30, 4, 5]);
}
Something more performant
Denis Lisov
@tanriol
Mar 03 16:03
Are you really seeing performance problems? There are other ways, but this should be performant too...
There's copy_from_slice as a more explicit way of doing the same.
octave99
@octave99
Mar 03 16:22
@tanriol Was trying to figure out if something better existed. Thanks for your input
Fredrik Portström
@portstrom
Mar 03 17:29

Can you point me to any known reason deriving Default on generic structs requires any type parameters to also implement Default, even if the type parameters are used only in positions that don't require this?

This doesn't work:

#[derive(Default)]
struct Test1<T> {
    _test: Vec<T>,
}

struct Test2;

fn main() {
    let _: Test1<Test2> = Default::default();
}

Doing the same thing without generics works:

#[derive(Default)]
struct Test1 {
    _test: Vec<Test2>,
}

struct Test2;

fn main() {
    let _: Test1 = Default::default();
}
Denis Lisov
@tanriol
Mar 03 17:59
This is a known problem, you can read some of the discussion in rust-lang/rust#26925
Fredrik Portström
@portstrom
Mar 03 18:27
@tanriol Thanks a lot :)