These are chat archives for rust-lang/rust

20th
Mar 2017
Aleksey Kladov
@matklad
Mar 20 2017 06:56
@btbvoy regarding unstable features on stable, you may find this discussion interesting: https://internals.rust-lang.org/t/getting-more-testing-of-unstable-features/4954
Pavel Meledin
@btbvoy
Mar 20 2017 13:04
@matklad thanks for link, looks really inetersting :-)
Vladimir
@Crazy-Owl
Mar 20 2017 19:47
For let x: String = ... what is the difference between &x and x.as_str()? Do I miss something or weren't these variants equivalent at some point of time?
Vladimir
@Crazy-Owl
Mar 20 2017 19:55
And another question: should I implement From<_> for my types or Into<_>? What is more idiomatic?
Sergey Noskov
@Albibek
Mar 20 2017 19:56

@Crazy-Owl From implies Into while backwards is not true, docs on Into recommend using From:

Library authors should not directly implement this trait, but should prefer implementing the From trait, which offers greater flexibility and provides an equivalent Into implementation for free, thanks to a blanket implementation in the standard library.

Ilya Bogdanov
@vitvakatu
Mar 20 2017 19:56
@Crazy-Owl From is more useful in most situations. And if you define From, then Into will be implemented by compiler
Vladimir
@Crazy-Owl
Mar 20 2017 19:56
okay, I see
thanks
Jacob Kiesel
@Xaeroxe
Mar 20 2017 19:57
Here's my next question: why do we have Into then? I've never understood the purpose of that
Ilya Bogdanov
@vitvakatu
Mar 20 2017 19:59
We need Into, even if it's implemented by compiler
Vladimir
@Crazy-Owl
Mar 20 2017 20:09
So basically, if I need a type that should be convertible to X, I should use Into<X> as my trait bound, but when implementing X, I should provide implementations of From<_> traits for types I want to be convertible?
Ilya Bogdanov
@vitvakatu
Mar 20 2017 20:11
I suppose, yes
Robey Pointer
@robey
Mar 20 2017 23:38
that case i pointed out last week, there’s no way to implement a From for