Skip to content

Commit 586b9f1

Browse files
authored
lower the msrv of sap to 1.85.0 (#5)
* use `core::str::from_utf8` instead of unstable `str::from_utf8` revert when rust-lang/rust#131114 is stable * remove todo comments and add comments with the rust version * fix comments and add links * use feature name in comments * use `String::from_utf8_lossy` instead of `OsStr::display` * update comments to add the new way of doing things * use the proper old way in the comment
1 parent 1b2dd43 commit 586b9f1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ where
223223
// however the user
224224
// can be as bright as Proxima Centauri
225225
// or as dark as Sagittarius A
226-
let str_arg = match str::from_utf8(arg) {
226+
//
227+
// `inherent_str_constructors` is not stabilised yet
228+
// https://github.com/rust-lang/rust/issues/131114
229+
// use `str::from_utf8(arg)` if you don't care about stable rust
230+
let str_arg = match core::str::from_utf8(arg) {
227231
Err(_e) => {
228232
let err = ParsingError::InvalidString;
229233
return Err(err);
@@ -257,7 +261,12 @@ where
257261
// might not be needed,
258262
// however i am not sure of the user's
259263
// eternal glory and shine
260-
let str_arg = match str::from_utf8(arg.as_encoded_bytes()) {
264+
//
265+
// `inherent_str_constructors` is not stabilised yet
266+
// https://github.com/rust-lang/rust/issues/131114
267+
// use `str::from_utf8(arg.as_encoded_bytes())`
268+
// if you don't care about stable rust
269+
let str_arg = match core::str::from_utf8(arg.as_encoded_bytes()) {
261270
Err(_e) => {
262271
let err = ParsingError::InvalidString;
263272
return Err(err);
@@ -353,14 +362,20 @@ impl Display for ParsingError {
353362
Self::InvalidOption { reason, offender } => {
354363
let reserve = write!(f, "reason: {reason}");
355364
if let Some(sentence) = offender {
356-
return write!(f, " at: {}", sentence.display());
365+
// `os_str_display` is stabilised in 1.87.0
366+
// https://github.com/rust-lang/rust/issues/120048
367+
// use `sentence.display()` if you don't care about rust <1.87.0
368+
return write!(f, " at: {}", String::from_utf8_lossy(sentence.as_bytes()));
357369
}
358370

359371
reserve
360372
}
361373

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

366381
Self::UnexpectedArg {

0 commit comments

Comments
 (0)