Skip to content

Conversation

steveklabnik
Copy link
Contributor

Slicing syntax should be used instead.

Fixes #25622

Slicing syntax should be used instead.

Fixes rust-lang#25622
@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

These conversions are actually intentionally remaining and are destined to become stable one day (not sure we've had the right revision to the RFC yet). The plan is to add explicit conversions between types (for example .as_slice, .as_os_str, .as_bytes, etc), in addition to AsRef implementations (where possible). These methods are very rarely used today, and most uses can be subsumed by deref coercions, but the convention is more widely applicable to other types (for example Path does not deref to OsStr but converting to one is done via .as_os_str).

I believe that @aturon is working on a PR to shard the global "core" feature, and hopefully these will be dealt with as a part of that!

@steveklabnik
Copy link
Contributor Author

Ah! Cool.

@bluss
Copy link
Contributor

bluss commented Jun 4, 2015

@alexcrichton I'm sceptical. We already have so many ways to do these conversions, I don't want Rust to be the language where "there's a thousand ways to do it".

@alexcrichton
Copy link
Member

Right, an RFC was intended to fill in the gaps here to clear it up, but the conventions are:

  • Implement the std::convert traits as necessary for your type.
  • If you have a very common conversion from one type to another (e.g. Path to OsStr, &T: Display to String) then a specific method is provided to perform the conversion.

This isn't just blanket adding methods for all conversions possible, as that's the point of the conversion traits to cut down on them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve documentation for Vec::as_slice

5 participants