mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
Correct safety docs
This commit is contained in:
parent
48d28aa689
commit
ddae7e6f41
2 changed files with 5 additions and 1 deletions
|
@ -2,6 +2,9 @@ use std::ffi::OsStr;
|
|||
|
||||
pub trait OsStrExt: private::Sealed {
|
||||
/// Converts to a string slice.
|
||||
///
|
||||
/// The Utf8Error is guaranteed to have a valid UTF8 boundary
|
||||
/// in its `valid_up_to()`
|
||||
fn try_str(&self) -> Result<&str, std::str::Utf8Error>;
|
||||
/// Returns `true` if the given pattern matches a sub-slice of
|
||||
/// this string slice.
|
||||
|
|
|
@ -463,7 +463,8 @@ fn split_nonutf8_once(b: &OsStr) -> (&str, Option<&OsStr>) {
|
|||
match b.try_str() {
|
||||
Ok(s) => (s, None),
|
||||
Err(err) => {
|
||||
// SAFETY: `char_indices` ensures `index` is at a valid UTF-8 boundary
|
||||
// SAFETY: `err.valid_up_to()`, which came from str::from_utf8(), is guaranteed
|
||||
// to be a valid UTF8 boundary
|
||||
let (valid, after_valid) = unsafe { ext::split_at(b, err.valid_up_to()) };
|
||||
let valid = valid.try_str().unwrap();
|
||||
(valid, Some(after_valid))
|
||||
|
|
Loading…
Reference in a new issue