-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add as_mut_os_string
to &mut PathBuf
and as_mut_os_str
to &mut Path
#140
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Comments
zertosh
added
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
labels
Nov 28, 2022
Seconded. Paths are arbitrary OS strings (per the existence of https://doc.rust-lang.org/std/path/struct.Path.html#method.new, among other things) so exposing mutation of one as an OS string should not be an issue. Please send a libstd PR. |
dtolnay
added
the
initial-comment-period
Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised.
label
Nov 28, 2022
This was referenced Nov 28, 2022
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 29, 2022
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str` Implements rust-lang/libs-team#140 (tracking issue rust-lang#105021).
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 29, 2022
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str` Implements rust-lang/libs-team#140 (tracking issue rust-lang#105021).
Unstable implementation PR: rust-lang/rust#105002 |
thomcc
pushed a commit
to tcdi/postgrestd
that referenced
this issue
Feb 10, 2023
thomcc
pushed a commit
to tcdi/postgrestd
that referenced
this issue
Feb 10, 2023
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str` Implements rust-lang/libs-team#140 (tracking issue #105021).
dtolnay
added
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
and removed
initial-comment-period
Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised.
labels
May 30, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
Currently there's:
&mut OsString
(or&mut OsStr
) from&mut PathBuf
(only fromPathBuf
viainto_os_string
), and;&mut OsStr
from&mut Path
.This puts
&mut OsString
'spush
, and&mut OsStr
'smake_ascii_lowercase
/make_ascii_uppercase
, out of reach for&mut PathBuf
and&mut Path
.Motivation, use-cases
The proposed API change makes it possible for
&mut PathBuf
/&mut OsStr
to take advantage of the APIs available on&mut OsString
and&mut OsStr
:&mut OsString
'spush
.PathBuf
'spush
extendsself
by adding path components, and can even clear the underlying path whenpush
ing an absolute path.OsString
always appends as-is.&mut PathBuf
without having to do an extra allocation in anOsString
to then append/replace on the&mut PathBuf
.&mut OsString
'sclear
,reserve
,try_reserve
,reserve_exact
,try_reserve_exact
,shrink_to_fit
,shrink_to
.&mut PathBuf
that are passthroughs to thePathBuf
's underlyingOsString
. So these would be of limited usefulness.&mut OsStr
'smake_ascii_lowercase
/make_ascii_uppercase
.There is already precedent for exposing a type's inner store via
as_mut_*
methods.String
has aas_mut_vec
andas_bytes_mut
(viaDeref<Target = str>
). These are markedunsafe
onString
because with them it is possible for the caller to break the type's "valid UTF-8" invariant. OnPathBuf
, the proposedas_mut_os_string
andas_mut_os_str
need not be markedunsafe
becausePathBuf
doesn't make any guarantees that can be broken byOsString
.Solution sketches
In
library/std/src/path.rs
:Links and related work
as_mut_os_string
oras_mut_os_str
be markedunsafe
?PathBuf
that would be broken by exposing the underlyingOsString
. So makingunsafe
is unnecessary. However, this proposal would make it impossible to offer any guarantee in the future. Given the stability of the API though, the possibility of offering some guarantee that would be broken by exposing safeas_mut_os_string
oras_mut_os_str
seems remote enough to not warrant the ergonomics loss of marking themunsafe
.What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: