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

Tracking Issue for os_str_display #120048

Open
2 of 4 tasks
riverbl opened this issue Jan 17, 2024 · 3 comments
Open
2 of 4 tasks

Tracking Issue for os_str_display #120048

riverbl opened this issue Jan 17, 2024 · 3 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@riverbl
Copy link
Contributor

riverbl commented Jan 17, 2024

Feature gate: #![feature(os_str_display)]

This is a tracking issue for the OsStr::display method.

Public API

// std::ffi

pub mod os_str {
    pub struct Display<'a> { /* private fields */ }
}

impl OsStr {
    pub fn display(&self) -> os_str::Display<'_>;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@riverbl riverbl added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 17, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2024
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2024
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2024
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 28, 2024
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 28, 2024
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 28, 2024
Rollup merge of rust-lang#120051 - riverbl:os-str-display, r=m-ou-se

Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see rust-lang/libs-team#326 (comment)).

- ACP: rust-lang/libs-team#326
- Tracking issue: rust-lang#120048
@ijackson
Copy link
Contributor

ijackson commented Mar 7, 2024

I'm concerned about the name. I think OsStr::to_string_lossy is the better precedent. Path has just display and I think this was a mistake.

These methods are really only suitable for use in diagnostics. Places where the stringlike thing is transformed for further use must necessarily either give up on handling invalid unicode (so should use a fallible method) or do something more complicated and awkward.

@ijackson
Copy link
Contributor

ijackson commented Mar 7, 2024

(Worst case behaviour from inappropriate use of these methods is modifying the wrong file.)

@riverbl
Copy link
Contributor Author

riverbl commented Apr 6, 2024

I'm concerned about the name. I think OsStr::to_string_lossy is the better precedent. Path has just display and I think this was a mistake.

Path has both to_string_lossy and display. OsStr already has to_string_lossy, which works in the same way as Path::to_string_lossy. This issue is for adding OsStr::display, which would work in the same way as Path::display.

These methods are really only suitable for use in diagnostics. Places where the stringlike thing is transformed for further use must necessarily either give up on handling invalid unicode (so should use a fallible method) or do something more complicated and awkward.

I've encountered situations where OsStr::display would be useful for displaying a potentially non Unicode file name to the user (example). In these cases, the lossy Unicode representation of the OsStr is not used beyond being displayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants