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

There is no way to create a PathBuf from an OsString without copying #22751

Closed
lilyball opened this issue Feb 24, 2015 · 6 comments
Closed

There is no way to create a PathBuf from an OsString without copying #22751

lilyball opened this issue Feb 24, 2015 · 6 comments
Assignees
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@lilyball
Copy link
Contributor

PathBuf doesn't expose any methods that can be used to create a PathBuf from an OsString (or anything convertible to an OsString) without copying. This seems like an unnecessary limitation.

/cc @aturon

@aturon
Copy link
Member

aturon commented Feb 24, 2015

Yep, just an oversight.

@aturon aturon added A-libs E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Feb 24, 2015
@LukasKalbertodt
Copy link
Member

Just add fn from_os_string(_: OsString) -> PathBuf to PathBuf? That seems too easy...

@alexcrichton
Copy link
Member

I think that this would probably be done by changing the AsOsStr bound on PathBuf::new instead to IntoOsString as one may also wish to construct a PathBuf from a String for example.

@retep998
Copy link
Member

cc me. I need this.

@lilyball
Copy link
Contributor Author

Nominating, I think this should be done before 1.0 as it may be a confusing omission.

@pnkfelix
Copy link
Member

1.0 beta, P-backcompat-libs (but only b/c @aturon said he's got a patch ready to go)

@pnkfelix pnkfelix added this to the 1.0 beta milestone Mar 19, 2015
aturon added a commit to aturon/rust that referenced this issue Mar 23, 2015
This commit:

* Introduces `std::convert`, providing an implementation of
RFC 529.

* Deprecates the `AsPath`, `AsOsStr`, and `IntoBytes` traits, all
in favor of the corresponding generic conversion traits.

  Consequently, various IO APIs now take `AsRef<Path>` rather than
`AsPath`, and so on. Since the types provided by `std` implement both
traits, this should cause relatively little breakage.

* Deprecates many `from_foo` constructors in favor of `from`.

* Changes `PathBuf::new` to take no argument (creating an empty buffer,
  as per convention). The previous behavior is now available as
  `PathBuf::from`.

* De-stabilizes `IntoCow`. It's not clear whether we need this separate trait.

Closes rust-lang#22751
Closes rust-lang#14433

[breaking-change]
@aturon aturon closed this as completed in 8389253 Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants