These are chat archives for rust-lang/rust

9th
Aug 2018
https://doc.rust-lang.org/std/fs/struct.File.html#method.open <-- how does Result<File> work when Result expects two type arguments.
Krys
@Krysme
Aug 09 2018 01:25 UTC
its a renamed type
I'm not finding anything googling for 'rust renamed type'
Is there another name it goes by?
Krys
@Krysme
Aug 09 2018 01:27 UTC
the result you see is actually in a different namespace
ah, by 'renamed type' you mean the type alias:
type Result<T> = Result<T, Error>;
?
Krys
@Krysme
Aug 09 2018 01:32 UTC
Indeed
Sorry for my poor English
this type alias has fixed the error type
Your English is fine, my point of confusion was: I was aware of std::result::Result<T, E> ... but I didn't realize that there was a std::io::Result that bound the E=Error
David Rojas Camaggi
@drojas
Aug 09 2018 01:58 UTC
hi, are syntax expressions capable of creating struct definitions from strings?
Franz Gregor
@fzgregor
Aug 09 2018 08:43 UTC
Is there some stable equivalent to Option::transpose?
Franz Gregor
@fzgregor
Aug 09 2018 08:48 UTC
thanks!
Michal 'vorner' Vaner
@vorner
Aug 09 2018 15:24 UTC
Let's say I have a TcpListener and run accept or incoming in one thread, so it is blocking. Is there a reasonable way to close and interrupt the listener from another thread?
Zakarum
@omni-viral
Aug 09 2018 16:32 UTC
@vorner It is impossible to close the listned cause you need to drop it.
You can connect to it to unblock. But this approach smell

int a, b, c, d, e, f; // in C
Is there a way to write that in Rust
right now, I have to write:

a: u32, b: u32, c: u32, d: u32, e: u32, f: u32,

Andrey Lesnikov
@ozkriff
Aug 09 2018 17:13 UTC
http://play.rust-lang.org/?gist=1c5ec1e80b83a0d6edae1d0b6b809cf2 you can use a tuple if you really want to declare multiple vars in one line
though their types still must be inferred from the context
Ichoran
@Ichoran
Aug 09 2018 17:16 UTC
I have found that most times in C I end up declaring variables separately anyway. It's usually clearer what is there.
In this case, this is for the dimensions of a tensor, so it's pretty much known to be u32
Lyle Mantooth
@IslandUsurper
Aug 09 2018 18:07 UTC
@qq00, you could write a macro to do that for you. But you should only do that if it actually makes it more readable/maintainable.
Ichoran
@Ichoran
Aug 09 2018 18:22 UTC

My instinct would be to

struct T6(u32, u32, u32, u32, u32, u32);

impl T6 {
    fn zero() -> T6 { T6(0, 0, 0, 0, 0, 0) }
}

let T6(a, b, c, d, e, f) = T6::zero();

That way I'd at least always get the right number of variables.

Ichoran
@Ichoran
Aug 09 2018 18:29 UTC
(Actually, I'd probably just struct T6{ a: u32, ... }. I probably want the whole set mutable if they're indices, and they make sense as a unit, and you don't really have any overhead from doing it that way AFAIK.)