These are chat archives for rust-lang/rust

1st
Oct 2015
Eliza Weisman
@hawkw
Oct 01 2015 18:31
Is there a way to specify in a where clause that a trait is NOT implemented for a type?
Peter Atashian
@retep998
Oct 01 2015 18:32
@hawkw where T: !Foo
Unfortunately I don't think Rust actually allows that yet, but that's the syntax you'd use if it was allowed
Jeroen Bollen
@Binero
Oct 01 2015 18:34
@retep998 It does allow negating markers like Send and Sync
Eliza Weisman
@hawkw
Oct 01 2015 18:35
Hmm. I want to implement a trait for a generic type when T: Display and use Display for formatting, but I also want to be able to use the debug formatter when T is not Display.
Jeroen Bollen
@Binero
Oct 01 2015 18:35
You'd want different output when debugging than when display-printing?
Eliza Weisman
@hawkw
Oct 01 2015 18:35
No, I want to fall back to Debug if T is not Display
Jeroen Bollen
@Binero
Oct 01 2015 18:35
Then why not just take anything that is Debug?
Eliza Weisman
@hawkw
Oct 01 2015 18:36
Because I'd rather use Display if it's available. I want to use Debug only as a fallback
Jeroen Bollen
@Binero
Oct 01 2015 18:36
Display is just an extension of Debug though, if a type implements Debug, it can automatically implement Display.
So you can just take a Debug.
That is unless you want different functionality between the two.
In that case I am unsure if you could just implement for Debug and Display seperately, and be explicit about wether to use Display or Debug when using the whatever-you-are-making.
Peter Atashian
@retep998
Oct 01 2015 18:39
Display is not an extension of Debug
It is completely valid for a type to implement Display and not implement Debug
Eliza Weisman
@hawkw
Oct 01 2015 18:46
Yeah. So I'd like to be able to implement my trait where T: Display and again where T: Debug, but have the T: Debug implementation only be used when T is not Display