These are chat archives for rust-lang/rust

2nd
May 2016
Daniel Collin
@emoon
May 02 2016 09:21
I doubt it will happen soon though but yeah :)
Daniel Collin
@emoon
May 02 2016 16:10

Can I write this

       if let Some(ref mut stream) = self.stream {
            stream.write(&data)
        } else {
            Ok((0))
        }

Using map/or_else something similar instead (function returns io::Result<()>

Erik Hedvall
@Ogeon
May 02 2016 16:15
You do it like this: self.stream.map_or(|s| s.write(&data), Ok((0))). Or do you mean that write returns io::Result<()>?
Daniel Collin
@emoon
May 02 2016 16:18
write returns io::Restult<()>
Erik Hedvall
@Ogeon
May 02 2016 16:19
Oh. And you want it to return 0 instead?
Daniel Collin
@emoon
May 02 2016 16:20
yes
I want to return something else if self.stream is None
I just wonder if I can do it using map & friends instead of the code shown
Erik Hedvall
@Ogeon
May 02 2016 16:22
Ok, what about self.stream.map_or(|s| s.write(&data).map(0), when_none)?
Daniel Collin
@emoon
May 02 2016 16:25
Thanks!
Hossein
@Hossein-Noroozpour
May 02 2016 17:27
hi guys, is there any way to exclude a trait in where clause
for example:
... where F: NotImplementTraitBlaBla
Zakarum
@omni-viral
May 02 2016 18:33
@Ogeon, I believe this would do exactly the same as code @emoon want to replace
self.stream.as_mut().map_or(Ok((0)), |s| s.write(&data))
Daniel Collin
@emoon
May 02 2016 18:36
@SCareAngel ah yes, that looks just what I want. thanks!
Zakarum
@omni-viral
May 02 2016 18:38
@emoon you're welcome
Sean Perry
@shaleh
May 02 2016 18:41
One liners are fun. But would that be considered proper, idiomatic style?
mhsjlw
@mhsjlw
May 02 2016 19:38
Really cool introductory Rust video : https://www.youtube.com/watch?v=U1EFgCNLDB8
Erik Hedvall
@Ogeon
May 02 2016 19:48
@SCareAngel looks like I accidentally swapped the arguments. Thanks for the correction :smile:
Zakarum
@omni-viral
May 02 2016 20:25
@Ogeon mostly important was as_mut to not destroy stream after code executed
Erik Hedvall
@Ogeon
May 02 2016 21:19
Oh, yeah. That too. I was too focused on getting the correct flow, and didn't test.
Boris Kuznetsov
@achempion
May 02 2016 23:14
Hi, I trying to figure out how to print value from each column of row of postgres result for several hours)
mhsjlw
@mhsjlw
May 02 2016 23:37
Hi! I've come across this stack overflow page on range : http://stackoverflow.com/a/9282338 and it seems that it isn't available any more... any ideas on alternatives ?
Ah seems I didn't look hard enough... my mistake 0...100 should have known that, sorry.
*.. not ...