-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC to add some additional utility methods to OsString and OsStr.
- Loading branch information
1 parent
8e2d3a3
commit 736bfce
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
- Feature Name: osstring_simple_functions | ||
- Start Date: 2015-10-04 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Add some additional utility methods to OsString and OsStr. | ||
|
||
# Motivation | ||
|
||
OsString and OsStr are extremely bare at the moment; some utilities would make them | ||
easier to work with. The given set of utilities is taken from String, and don't add | ||
any additional restrictions to the implementation. | ||
|
||
I don't think any of the proposed methods are controversial. | ||
|
||
# Detailed design | ||
|
||
Add the following methods to OsString: | ||
|
||
```rust | ||
/// Creates a new `OsString` with the given capacity. The string will be able | ||
/// to hold exactly `capacity` bytes without reallocating. If `capacity` is 0, | ||
/// the string will not allocate. | ||
/// | ||
/// See main `OsString` documentation information about encoding. | ||
fn with_capacity(capacity: usize) -> OsString; | ||
|
||
/// Truncates `self` to zero length. | ||
fn clear(&mut self); | ||
|
||
/// Returns the number of bytes this `OsString` can hold without reallocating. | ||
/// | ||
/// See `OsString` introduction for information about encoding. | ||
fn capacity(&self) -> usize; | ||
|
||
/// Reserves capacity for at least `additional` more bytes to be inserted in the | ||
/// given `OsString`. The collection may reserve more space to avoid frequent | ||
/// reallocations. | ||
fn reserve(&mut self, additional: usize); | ||
|
||
/// Reserves the minimum capacity for exactly `additional` more bytes to be | ||
/// inserted in the given `OsString`. Does nothing if the capacity is already | ||
/// sufficient. | ||
/// | ||
/// Note that the allocator may give the collection more space than it | ||
/// requests. Therefore capacity can not be relied upon to be precisely | ||
/// minimal. Prefer reserve if future insertions are expected. | ||
fn reserve_exact(&mut self, additional: usize); | ||
``` | ||
|
||
Add the following methods to OsStr: | ||
|
||
```rust | ||
/// Checks whether `self` is empty. | ||
fn is_empty(&self) -> bool; | ||
|
||
/// Returns the number of bytes in this string. | ||
/// | ||
/// See `OsStr` introduction for information about encoding. | ||
fn len(&self) -> usize; | ||
``` | ||
|
||
# Drawbacks | ||
|
||
The meaning of `len()` might be a bit confusing because it's the size of | ||
the internal representation on Windows, which isn't otherwise visible to the | ||
user. | ||
|
||
# Alternatives | ||
|
||
None. | ||
|
||
# Unresolved questions | ||
|
||
None. |