Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ where
// however the user
// can be as bright as Proxima Centauri
// or as dark as Sagittarius A
let str_arg = match str::from_utf8(arg) {
//
// `inherent_str_constructors` is not stabilised yet
// https://github.com/rust-lang/rust/issues/131114
// use `str::from_utf8(arg)` if you don't care about stable rust
let str_arg = match core::str::from_utf8(arg) {
Err(_e) => {
let err = ParsingError::InvalidString;
return Err(err);
Expand Down Expand Up @@ -257,7 +261,12 @@ where
// might not be needed,
// however i am not sure of the user's
// eternal glory and shine
let str_arg = match str::from_utf8(arg.as_encoded_bytes()) {
//
// `inherent_str_constructors` is not stabilised yet
// https://github.com/rust-lang/rust/issues/131114
// use `str::from_utf8(arg.as_encoded_bytes())`
// if you don't care about stable rust
let str_arg = match core::str::from_utf8(arg.as_encoded_bytes()) {
Err(_e) => {
let err = ParsingError::InvalidString;
return Err(err);
Expand Down Expand Up @@ -353,14 +362,20 @@ impl Display for ParsingError {
Self::InvalidOption { reason, offender } => {
let reserve = write!(f, "reason: {reason}");
if let Some(sentence) = offender {
return write!(f, " at: {}", sentence.display());
// `os_str_display` is stabilised in 1.87.0
// https://github.com/rust-lang/rust/issues/120048
// use `sentence.display()` if you don't care about rust <1.87.0
return write!(f, " at: {}", String::from_utf8_lossy(sentence.as_bytes()));
}

reserve
}

Self::UnconsumedValue { value } => {
write!(f, "leftover value: {}", value.display())
// `os_str_display` is stabilised in 1.87.0
// https://github.com/rust-lang/rust/issues/120048
// use `value.display()` if you don't care about rust <1.87.0
write!(f, "leftover value: {}", String::from_utf8_lossy(value.as_bytes()))
}

Self::UnexpectedArg {
Expand Down