Skip to main content

Bounds

Trait Bounds 

Source
pub(crate) trait Bounds: Sized {
    type Primitive: Primitive;

    const WHAT: &'static str;
    const MIN: Self::Primitive;
    const MAX: Self::Primitive;

    // Required method
    fn error() -> BoundsError;

    // Provided methods
    fn check(n: impl Into<i64>) -> Result<Self::Primitive, BoundsError> { ... }
    fn check128(n: impl Into<i128>) -> Result<Self::Primitive, BoundsError> { ... }
    fn check_self(n: Self::Primitive) -> Result<Self::Primitive, BoundsError> { ... }
    fn parse(bytes: &[u8]) -> Result<Self::Primitive, Error> { ... }
    fn checked_add(
        n1: Self::Primitive,
        n2: Self::Primitive,
    ) -> Result<Self::Primitive, BoundsError> { ... }
    fn checked_sub(
        n1: Self::Primitive,
        n2: Self::Primitive,
    ) -> Result<Self::Primitive, BoundsError> { ... }
    fn checked_mul(
        n1: Self::Primitive,
        n2: Self::Primitive,
    ) -> Result<Self::Primitive, BoundsError> { ... }
}
Expand description

An interface for defining boundaries on integer values.

Required Associated Constants§

Source

const WHAT: &'static str

A short human readable description of the values represented by these bounds.

Source

const MIN: Self::Primitive

The minimum boundary value.

Source

const MAX: Self::Primitive

The maximum boundary value.

Required Associated Types§

Source

type Primitive: Primitive

The primitive integer representation for this boundary type.

This is generally the smallest primitive integer type that fits the minimum and maximum allowed values.

Required Methods§

Source

fn error() -> BoundsError

Create an error when a value is outside the bounds for this type.

Provided Methods§

Source

fn check(n: impl Into<i64>) -> Result<Self::Primitive, BoundsError>

Converts the 64-bit integer provided into the primitive representation of these bounds.

§Errors

This returns an error if the given integer does not fit in the bounds prescribed by this trait implementation.

§Panics

This panics when debug_assertions are enabled if the bounds of this implementation exceed what is representable in an i64. In this case, callers must use check128.

Source

fn check128(n: impl Into<i128>) -> Result<Self::Primitive, BoundsError>

Converts the 128-bit integer provided into the primitive representation of these bounds.

§Errors

This returns an error if the given integer does not fit in the bounds prescribed by this trait implementation.

Source

fn check_self(n: Self::Primitive) -> Result<Self::Primitive, BoundsError>

Checks whether the given integer, in the same primitive representation as this boundary type, is in bounds.

§Errors

This returns an error if the given integer does not fit in the bounds prescribed by this trait implementation.

Source

fn parse(bytes: &[u8]) -> Result<Self::Primitive, Error>

Parses a 64-bit integer from the beginning to the end of the given slice of bytes.

Note that this can never parse a negative integer since it doesn’t look for a sign. On success, the integer returned is always positive.

§Errors

If the given slice is not a valid integer (i.e., overflow or contains anything other than [0-9]) or is not in the bounds for this trait implementation, then an error is returned.

Note that the error can either be a parsing error or it can be a boundary error.

Source

fn checked_add( n1: Self::Primitive, n2: Self::Primitive, ) -> Result<Self::Primitive, BoundsError>

Performs checked addition using this boundary type’s primitive representation.

§Errors

If the result exceeds the boundaries of the primitive type or of the declared range for this type, then an error is returned.

Source

fn checked_sub( n1: Self::Primitive, n2: Self::Primitive, ) -> Result<Self::Primitive, BoundsError>

Performs checked subtraction using this boundary type’s primitive representation.

§Errors

If the result exceeds the boundaries of the primitive type or of the declared range for this type, then an error is returned.

Source

fn checked_mul( n1: Self::Primitive, n2: Self::Primitive, ) -> Result<Self::Primitive, BoundsError>

Performs checked multiplication using this boundary type’s primitive representation.

§Errors

If the result exceeds the boundaries of the primitive type or of the declared range for this type, then an error is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Bounds for Century

Source§

const WHAT: &'static str = "century"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 99

Source§

type Primitive = i8

Source§

impl Bounds for CivilDayNanosecond

Source§

const WHAT: &'static str = "nanoseconds (in one civil day)"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for CivilDaySecond

Source§

const WHAT: &'static str = "seconds (in one civil day)"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for Day

Source§

const WHAT: &'static str = "day"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 31

Source§

type Primitive = i8

Source§

impl Bounds for DayOfYear

Source§

const WHAT: &'static str = "day-of-year"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 366

Source§

type Primitive = i16

Source§

impl Bounds for Hour12

Source§

const WHAT: &'static str = "hour (12 hour clock)"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 12

Source§

type Primitive = i8

Source§

impl Bounds for Hour

Source§

const WHAT: &'static str = "hour"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 23

Source§

type Primitive = i8

Source§

impl Bounds for ISOWeek

Source§

const WHAT: &'static str = "iso-week"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 53

Source§

type Primitive = i8

Source§

impl Bounds for ISOYear

Source§

const WHAT: &'static str = "iso-year"

Source§

const MIN: Self::Primitive = -9999

Source§

const MAX: Self::Primitive = 9999

Source§

type Primitive = i16

Source§

impl Bounds for Increment32

Source§

const WHAT: &'static str = "rounding increment"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 1_000_000_000

Source§

type Primitive = i32

Source§

impl Bounds for Increment

Source§

const WHAT: &'static str = "rounding increment"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 1_000_000_000

Source§

type Primitive = i64

Source§

impl Bounds for LeapSecond

Source§

const WHAT: &'static str = "second"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 60

Source§

type Primitive = i8

Source§

impl Bounds for Microsecond

Source§

const WHAT: &'static str = "microsecond"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 999

Source§

type Primitive = i16

Source§

impl Bounds for Millisecond

Source§

const WHAT: &'static str = "millisecond"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 999

Source§

type Primitive = i16

Source§

impl Bounds for Minute

Source§

const WHAT: &'static str = "minute"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 59

Source§

type Primitive = i8

Source§

impl Bounds for Month

Source§

const WHAT: &'static str = "month"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 12

Source§

type Primitive = i8

Source§

impl Bounds for Nanosecond

Source§

const WHAT: &'static str = "nanosecond"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 999

Source§

type Primitive = i16

Source§

impl Bounds for NthWeekday

Source§

const WHAT: &'static str = "nth weekday"

Source§

const MIN: Self::Primitive = SpanWeeks::MIN

Source§

const MAX: Self::Primitive = SpanWeeks::MAX

Source§

type Primitive = i32

Source§

impl Bounds for OffsetHours

Source§

const WHAT: &'static str = "time zone offset hours"

Source§

const MIN: Self::Primitive = -25

Source§

const MAX: Self::Primitive = 25

Source§

type Primitive = i8

Source§

impl Bounds for OffsetMinutes

Source§

const WHAT: &'static str = "time zone offset minutes"

Source§

const MIN: Self::Primitive = -59

Source§

const MAX: Self::Primitive = 59

Source§

type Primitive = i8

Source§

impl Bounds for OffsetSeconds

Source§

const WHAT: &'static str = "time zone offset seconds"

Source§

const MIN: Self::Primitive = -59

Source§

const MAX: Self::Primitive = 59

Source§

type Primitive = i8

Source§

impl Bounds for OffsetTotalSeconds

Source§

const WHAT: &'static str = "time zone offset total seconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for Second

Source§

const WHAT: &'static str = "second"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 59

Source§

type Primitive = i8

Source§

impl Bounds for SignedDurationSeconds

Source§

const WHAT: &'static str = "signed duration seconds"

Source§

const MIN: Self::Primitive = i64::MIN

Source§

const MAX: Self::Primitive = i64::MAX

Source§

type Primitive = i64

Source§

impl Bounds for SignedSubsecNanosecond

Source§

const WHAT: &'static str = "subsecond nanosecond"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive = SubsecNanosecond::MAX

Source§

type Primitive = i32

Source§

impl Bounds for SpanDays

Source§

const WHAT: &'static str = "days"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for SpanHours

Source§

const WHAT: &'static str = "hours"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for SpanMicroseconds

Source§

const WHAT: &'static str = "microseconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for SpanMilliseconds

Source§

const WHAT: &'static str = "milliseconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for SpanMinutes

Source§

const WHAT: &'static str = "minutes"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for SpanMonths

Source§

const WHAT: &'static str = "months"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for SpanMultiple

Source§

const WHAT: &'static str = "span multiple"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive = i64::MAX

Source§

type Primitive = i64

Source§

impl Bounds for SpanNanoseconds

Source§

const WHAT: &'static str = "nanoseconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive = i64::MAX

Source§

type Primitive = i64

Source§

impl Bounds for SpanSeconds

Source§

const WHAT: &'static str = "seconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for SpanWeeks

Source§

const WHAT: &'static str = "weeks"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for SpanYears

Source§

const WHAT: &'static str = "years"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i16

Source§

impl Bounds for SubsecNanosecond

Source§

const WHAT: &'static str = "subsecond nanosecond"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for UnixEpochDays

Source§

const WHAT: &'static str = "Unix epoch days"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32

Source§

impl Bounds for UnixMicroseconds

Source§

const WHAT: &'static str = "Unix timestamp microseconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for UnixMilliseconds

Source§

const WHAT: &'static str = "Unix timestamp milliseconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for UnixSeconds

Source§

const WHAT: &'static str = "Unix timestamp seconds"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for WeekNum

Source§

const WHAT: &'static str = "week-number"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 53

Source§

type Primitive = i8

Source§

impl Bounds for WeekdayMondayOne

Source§

const WHAT: &'static str = "weekday (Monday 1-indexed)"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 7

Source§

type Primitive = i8

Source§

impl Bounds for WeekdayMondayZero

Source§

const WHAT: &'static str = "weekday (Monday 0-indexed)"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 6

Source§

type Primitive = i8

Source§

impl Bounds for WeekdaySundayOne

Source§

const WHAT: &'static str = "weekday (Sunday 1-indexed)"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = 7

Source§

type Primitive = i8

Source§

impl Bounds for WeekdaySundayZero

Source§

const WHAT: &'static str = "weekday (Sunday 0-indexed)"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 6

Source§

type Primitive = i8

Source§

impl Bounds for Year

Source§

const WHAT: &'static str = "year"

Source§

const MIN: Self::Primitive = -9999

Source§

const MAX: Self::Primitive = 9999

Source§

type Primitive = i16

Source§

impl Bounds for YearBCE

Source§

const WHAT: &'static str = "BCE year"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive

Source§

type Primitive = i16

Source§

impl Bounds for YearCE

Source§

const WHAT: &'static str = "CE year"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive = Year::MAX

Source§

type Primitive = i16

Source§

impl Bounds for YearTwoDigit

Source§

const WHAT: &'static str = "year (2 digits)"

Source§

const MIN: Self::Primitive = 0

Source§

const MAX: Self::Primitive = 99

Source§

type Primitive = i16

Source§

impl Bounds for ZonedDayNanoseconds

Source§

const WHAT: &'static str = "nanoseconds (in one zoned datetime day)"

Source§

const MIN: Self::Primitive

Source§

const MAX: Self::Primitive

Source§

type Primitive = i64

Source§

impl Bounds for ZonedDaySeconds

Source§

const WHAT: &'static str = "seconds (in one zoned datetime day)"

Source§

const MIN: Self::Primitive = 1

Source§

const MAX: Self::Primitive

Source§

type Primitive = i32