These are chat archives for rust-lang/rust

12th
Jul 2018
Manuel Holtgrewe
@holtgrewe
Jul 12 2018 09:04
Hi. What's the recommended way of using Logger from slog in tests? The function I want to test needs a &Logger argument. I don't care about the log output in tests.
Vegar Ringdal
@vegarringdal
Jul 12 2018 10:45
Learning rust, but not having ; on last line if function returns when not using word return gets me every time.
jazzbuck
@jazzbuck
Jul 12 2018 10:53
^ikr
Manuel Holtgrewe
@holtgrewe
Jul 12 2018 10:58
@vegarringdal make sure to have an editor with RLS support such as Visual Studio Code. You'll get a visual notification about such simple problems.
Vegar Ringdal
@vegarringdal
Jul 12 2018 11:09
@holtgrewe Yes, I have that, but error message when hovering isnt always self explaining :-)
image.png
Its also says consider removing this semicolon if I hover the semicolon.
But for now vscode have been really great, do you know if there is been worked on debugging for vscode (windows)
Zakarum
@omni-viral
Jul 12 2018 14:04
If I want to transmute Foo<T> to Foo<U> when type parameter is only used within PhantomData field is it enough to use repr(C)?
Dmitriy
@dpogretskiy
Jul 12 2018 14:07
not sure, but maybe
repr(C) can mess stuff up, too much of a delicate case
Judson Lester
@nyarly
Jul 12 2018 17:06
Is it possible to search crates.io for pairs of keywords?
Zakarum
@omni-viral
Jul 12 2018 19:17
Try on crates.rs
Judson Lester
@nyarly
Jul 12 2018 20:00
I don't see a way to do it in either place.
I'd like to be able to add a link in docs to e.g. gotham+middleware but there doesn't seem to be a way?
Robert Winslow
@rw
Jul 12 2018 21:12
I want to use generics as "labels" to help avoid programming errors. I've been using () type aliases to achieve this. However, when I use them, the types that are aliased to () are automatically coerced to each other, which makes them useless for my purposes. In short, I want to make this code not compile--how should I do that? https://play.rust-lang.org/?gist=ce42fda2d99966c33fdc425924772eb1&version=stable&mode=debug&edition=2015
Denis Lisov
@tanriol
Jul 12 2018 21:27
Type aliases exist for convenience, not safety. I'd suggest using just struct A;
Denis Lisov
@tanriol
Jul 12 2018 21:28
Or wrappers like struct A(u64);
@nyarly The link is the same; have you forgotten to re-share it?
I assumed the link would change as I hit Run - dunno why.
It's essentially what you're suggesting, but with enums.
Denis Lisov
@tanriol
Jul 12 2018 21:33
I'm not exactly sure whether anything guarantees how PhantomData<UninhabitedType> works. I'd actually expect it to be uninhabited too (it behaves "as if" there was a T inside, which for an uninhabited T means "cannot exist"), so kinda surprised it works.
Robert Winslow
@rw
Jul 12 2018 21:37
@nyarly thanks, that enum trick is a quick way to do it like how i am trying to!
@tanriol i think you're suggesting that i keep the value in the child type, not the parent. do you think that would be more idiomatic?
Sylwester Rąpała
@xoac
Jul 12 2018 21:55
        for i: Rep in 0..size {
            inner.insert((i, 0), i);
        }
how can I specify i type?
Denis Lisov
@tanriol
Jul 12 2018 21:56
@rw By the way, you're not trying to label physical units, are you?
@xoac Which type?
I would like to use commented
Robert Winslow
@rw
Jul 12 2018 22:07
@tanriol no, just reduce programming errors for a serialization format
Denis Lisov
@tanriol
Jul 12 2018 22:09
Well, for me Offset(0x1000) looks more natural than LabeledValue::<Offset>(0x1000)
@xoac Not like this. Is your iterator generic over the item type?
Robert Winslow
@rw
Jul 12 2018 22:15
@tanriol thanks for your help! :-)
Sylwester Rąpała
@xoac
Jul 12 2018 22:19
@tanriol I solved my problem. I used 0..size where size was accidentally usize and should be u32
Ichoran
@Ichoran
Jul 12 2018 22:45
@xaoc - You can't (yet) do type ascription like that, but you can specify the range with a type parameter, e.g.:
    let r: std::ops::Range<Rep> = 0..5;
    for i in r { println!("{}", i); }