These are chat archives for rust-lang/rust

1st
Sep 2018
inv2004
@inv2004
Sep 01 2018 01:17
Hi. Can someone recommend if it possible to resolve it without custom deserializer ? https://play.rust-lang.org/?gist=d5570c505ded0b2dddd1f5723bcfdac4&version=nightly&mode=debug&edition=2015
Robert
@rw
Sep 01 2018 01:37

hi! i'd like help writing a function signature. i have a slice, and the element type must impl X. additionally, i'd like to support a slice of values, or a slice of references. what i have so far is this:

impl X for T {}
impl<'a> X for &'a T {}
fn foo<T: X>(items: &[T])

should i be using Borrow or AsRef instead?

Vitaly
@Virtuos86
Sep 01 2018 02:13
@rw if items is immutable in foo's block then I would prefer AsRef in your case.
Robert
@rw
Sep 01 2018 02:14
@Virtuos86 so it would be
fn foo<T: AsRef<X>>(items: &[T])
?
Robert
@rw
Sep 01 2018 02:20
@Virtuos86 discussing with you on users.rust-lang.org :-)
Vitaly
@Virtuos86
Sep 01 2018 03:51
@rw What does T: AsRef <X> mean?
@rw ok
Kelly Thomas Kline
@kellytk
Sep 01 2018 07:22
I'm viewing a Rust project with the latest Mac VS Code. How can I cause actix of use actix::prelude::*; to become a hyperlink into its code? Holding the command key while hovering usually does that but not in this case for some reason
Sylwester Rąpała
@xoac
Sep 01 2018 08:40
or maybe there is some replacement? I would like to read more about errors architectures. And how I should it do in rust
Sam Johnson
@sam0x17
Sep 01 2018 20:02
are match expressions in rust O(1)?
Denis Lisov
@tanriol
Sep 01 2018 20:04
@sam0x17 Please detail your question :-) what number do you expect to be big?
Sam Johnson
@sam0x17
Sep 01 2018 20:05
as in are they like C++ switch statements or are they slower like a bunch of if elses
Denis Lisov
@tanriol
Sep 01 2018 20:08
I'd guess they're optimized roughly to the same degree... but it you expect them to be a performance bottleneck, you should benchmark it :-)
Sam Johnson
@sam0x17
Sep 01 2018 20:08
as in do they get optimized to a jump table lookup when applicable
thanks
Kelly Thomas Kline
@kellytk
Sep 01 2018 20:42
Is panic! what I should use when testing program state that should not exist?
Kelly Thomas Kline
@kellytk
Sep 01 2018 20:56
And related, how can an Option type be used to evaluate to true if it's Some()?
Sylwester Rąpała
@xoac
Sep 01 2018 21:24
@kellytk is_some()?
@kellytk There is more panic!'s macros. For example unimplemented!() unreachable!()and panic!() as the most general.
Kelly Thomas Kline
@kellytk
Sep 01 2018 21:30
I see that panic! takes the message, not a bool, so would convention be to wrap the panic in an if expression? In other languages I can pass a bool and error message directly to the exception macro/function
Zakarum
@omni-viral
Sep 01 2018 21:31
@kellytk assert! takes bool
There are other assert_*! macro
Unlike other languages it is not debug-only statement. debug_assert family are debug-only
Kelly Thomas Kline
@kellytk
Sep 01 2018 21:36
assert! is what I was looking for, thank you @omni-viral and @xoac