mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
join: fix workaround for IntErrorKind
In Rust versions before 1.55, there was no enum for parse errors. With the bump of the MSRV to 1.56 we can simplify this.
This commit is contained in:
parent
4701ea0c95
commit
0fc667730d
1 changed files with 2 additions and 5 deletions
|
@ -18,6 +18,7 @@ use std::error::Error;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Split, Stdin, Write};
|
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Split, Stdin, Write};
|
||||||
|
use std::num::IntErrorKind;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
|
@ -965,13 +966,9 @@ fn get_field_number(keys: Option<usize>, key: Option<usize>) -> UResult<usize> {
|
||||||
/// Parse the specified field string as a natural number and return
|
/// Parse the specified field string as a natural number and return
|
||||||
/// the zero-based field number.
|
/// the zero-based field number.
|
||||||
fn parse_field_number(value: &str) -> UResult<usize> {
|
fn parse_field_number(value: &str) -> UResult<usize> {
|
||||||
// TODO: use ParseIntError.kind() once MSRV >= 1.55
|
|
||||||
// For now, store an overflow Err from parsing a value 10x 64 bit usize::MAX
|
|
||||||
// Adapted from https://github.com/rust-lang/rust/issues/22639
|
|
||||||
let overflow = "184467440737095516150".parse::<usize>().err().unwrap();
|
|
||||||
match value.parse::<usize>() {
|
match value.parse::<usize>() {
|
||||||
Ok(result) if result > 0 => Ok(result - 1),
|
Ok(result) if result > 0 => Ok(result - 1),
|
||||||
Err(ref e) if *e == overflow => Ok(usize::MAX),
|
Err(e) if e.kind() == &IntErrorKind::PosOverflow => Ok(usize::MAX),
|
||||||
_ => Err(USimpleError::new(
|
_ => Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("invalid field number: {}", value.quote()),
|
format!("invalid field number: {}", value.quote()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue