Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make String/str, Vec/[] conversions more ergonomic #14983

Closed
brson opened this issue Jun 17, 2014 · 9 comments
Closed

Make String/str, Vec/[] conversions more ergonomic #14983

brson opened this issue Jun 17, 2014 · 9 comments
Labels
P-medium Medium priority
Milestone

Comments

@brson
Copy link
Contributor

brson commented Jun 17, 2014

There's a lot of code right now that does things like frob(&"foo".to_string()).as_slice(), using method calls to do both 'free' and non-free coercions. While the underlying string semantics may be good, it's not so usable as one might like.

We need to figure out a way to minimize the burden of these, and other, coercion methods without compromising predictability.

Nominating.

@nikomatsakis
Copy link
Contributor

cc me

@brson
Copy link
Contributor Author

brson commented Jun 17, 2014

Another consideration regarding coercions: There are a number of constructors in std that want to take something like fn open<T: SomethingLikeAPath>(path: T). We have in the past decided not to do this and force callers to do explicit conversions, but people don't like it. These are cropping up more and more. @alexcrichton knows specific examples.

@steveklabnik
Copy link
Member

In Ruby, we have standard methods that convert things. If the call-ee wants a string, it will call to_s on the argument, so you can know that it's a string for the rest of the body.

I would expect this would be against the 'zero cost' mentality, though.

@brson brson added P-high and removed I-nominated labels Jun 19, 2014
@brson brson added this to the 1.0 milestone Jun 19, 2014
@brson
Copy link
Contributor Author

brson commented Jun 19, 2014

1.0, P-high.

@nixpulvis
Copy link

I know rust doesn't really have a notion of a constructor function, but could this be a good case for the addition of a cast constructor, allowing for implicit casts. Totally a design decision, just wondering. This is defiantly one of my least favorite things about programming in rust at the moment.

@aturon
Copy link
Member

aturon commented Sep 11, 2014

Note, the slice notation RFC would help here.

@japaric
Copy link
Member

japaric commented Nov 4, 2014

String/Vec<T> implement Deref<str>/Deref<[T]> , and we now have slicing [a..b] sugar. Can this be considered solved?

@alexcrichton
Copy link
Member

I would think so! Nominating to be closed at the next triage meeting.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 6, 2014

team believes the issues here either are or will be handled by un-feature gating slice notation and/or other items in the RFC pipeline (such as deref coercions). Closing.

@pnkfelix pnkfelix closed this as completed Nov 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

8 participants