These are chat archives for rust-lang/rust

9th
Aug 2018
qq00
@qq00
Aug 09 2018 01:22
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
its a renamed type
qq00
@qq00
Aug 09 2018 01:25
I'm not finding anything googling for 'rust renamed type'
Is there another name it goes by?
Krys
@Krysme
Aug 09 2018 01:27
the result you see is actually in a different namespace
qq00
@qq00
Aug 09 2018 01:27
ah, by 'renamed type' you mean the type alias:
type Result<T> = Result<T, Error>;
?
Krys
@Krysme
Aug 09 2018 01:32
Indeed
Sorry for my poor English
this type alias has fixed the error type
qq00
@qq00
Aug 09 2018 01:35
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
hi, are syntax expressions capable of creating struct definitions from strings?
Franz Gregor
@fzgregor
Aug 09 2018 08:43
Is there some stable equivalent to Option::transpose?
Franz Gregor
@fzgregor
Aug 09 2018 08:48
thanks!
Michal 'vorner' Vaner
@vorner
Aug 09 2018 15:24
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
@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
qq00
@qq00
Aug 09 2018 16:49

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
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
I have found that most times in C I end up declaring variables separately anyway. It's usually clearer what is there.
qq00
@qq00
Aug 09 2018 17:49
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
@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

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
(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.)