Skip to content

Commit 20b27cb

Browse files
committed
Rename OutOfRangeError to ConversionRangeError
1 parent 4c43ec3 commit 20b27cb

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

src/duration.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "std")]
22
use crate::Instant;
33
use crate::{
4-
NumberExt, OutOfRangeError,
4+
NumberExt, ConversionRangeError,
55
Sign::{self, Negative, Positive, Zero},
66
};
77
use core::{
@@ -843,7 +843,7 @@ impl Duration {
843843
since = "0.2.0",
844844
note = "Use `Duration::try_from(value)` or `value.try_into()`"
845845
)]
846-
pub fn from_std(std: StdDuration) -> Result<Self, OutOfRangeError> {
846+
pub fn from_std(std: StdDuration) -> Result<Self, ConversionRangeError> {
847847
std.try_into()
848848
}
849849

@@ -853,35 +853,35 @@ impl Duration {
853853
since = "0.2.0",
854854
note = "Use `std::time::Duration::try_from(value)` or `value.try_into()`"
855855
)]
856-
pub fn to_std(&self) -> Result<StdDuration, OutOfRangeError> {
856+
pub fn to_std(&self) -> Result<StdDuration, ConversionRangeError> {
857857
if self.sign.is_negative() {
858-
Err(OutOfRangeError)
858+
Err(ConversionRangeError)
859859
} else {
860860
Ok(self.std)
861861
}
862862
}
863863
}
864864

865865
impl TryFrom<StdDuration> for Duration {
866-
type Error = OutOfRangeError;
866+
type Error = ConversionRangeError;
867867

868868
#[inline(always)]
869-
fn try_from(original: StdDuration) -> Result<Self, OutOfRangeError> {
869+
fn try_from(original: StdDuration) -> Result<Self, ConversionRangeError> {
870870
some_if_in_range!(Self {
871871
sign: original.as_nanos().sign(),
872872
std: original,
873873
})
874-
.ok_or(OutOfRangeError)
874+
.ok_or(ConversionRangeError)
875875
}
876876
}
877877

878878
impl TryFrom<Duration> for StdDuration {
879-
type Error = OutOfRangeError;
879+
type Error = ConversionRangeError;
880880

881881
#[inline(always)]
882-
fn try_from(duration: Duration) -> Result<Self, OutOfRangeError> {
882+
fn try_from(duration: Duration) -> Result<Self, ConversionRangeError> {
883883
if duration.sign.is_negative() {
884-
Err(OutOfRangeError)
884+
Err(ConversionRangeError)
885885
} else {
886886
Ok(duration.std)
887887
}

src/lib.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,28 +315,19 @@ mod no_std_prelude {
315315

316316
/// An error type indicating that a conversion failed because the target type
317317
/// could not store the initial value.
318-
///
319-
/// ```rust
320-
/// # use time::{Duration, OutOfRangeError};
321-
/// # use core::time::Duration as StdDuration;
322-
/// # use core::{any::Any, convert::TryFrom};
323-
/// // "Construct" an `OutOfRangeError`.
324-
/// let error = StdDuration::try_from(Duration::seconds(-1)).unwrap_err();
325-
/// assert!(Any::is::<OutOfRangeError>(&error));
326-
/// ```
327318
#[non_exhaustive]
328319
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
329-
pub struct OutOfRangeError;
320+
pub struct ConversionRangeError;
330321

331-
impl fmt::Display for OutOfRangeError {
322+
impl fmt::Display for ConversionRangeError {
332323
#[inline(always)]
333324
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> core::fmt::Result {
334325
f.write_str("Source value is out of range for the target type")
335326
}
336327
}
337328

338329
#[cfg(feature = "std")]
339-
impl std::error::Error for OutOfRangeError {}
330+
impl std::error::Error for ConversionRangeError {}
340331

341332
#[cfg(test)]
342333
mod test {
@@ -347,7 +338,7 @@ mod test {
347338
#[test]
348339
fn out_of_range_error_format() {
349340
assert_eq!(
350-
OutOfRangeError.to_string(),
341+
ComponentRangeError.to_string(),
351342
"Source value is out of range for the target type",
352343
);
353344
}

0 commit comments

Comments
 (0)