pub enum IntegerType {
Smallint,
Integer,
Bigint,
}Expand description
A PostgreSQL integer type, ordered from the narrowest to the widest.
use sql_values::postgres::{CastError, BuiltinType, CastValue, IntegerType, cast_value};
assert_eq!(IntegerType::Smallint.range(), -32_768..=32_767);
assert_eq!(IntegerType::Smallint.wider(IntegerType::Integer), IntegerType::Integer);
assert_eq!(IntegerType::Integer.value(7), Ok(CastValue::Integer(7)));
assert_eq!(
IntegerType::Smallint.value(40_000),
Err(CastError::OutOfRange(BuiltinType::Smallint)),
);
assert_eq!(IntegerType::try_from(BuiltinType::Bigint), Ok(IntegerType::Bigint));
assert_eq!(IntegerType::try_from(BuiltinType::Text), Err(BuiltinType::Text));
// `value` is the cast from `bigint` to the type.
for integer in [IntegerType::Smallint, IntegerType::Integer, IntegerType::Bigint] {
assert_eq!(cast_value(CastValue::Bigint(7), integer.into()), integer.value(7).map(Some));
}Variants§
Implementations§
Source§impl IntegerType
impl IntegerType
Sourcepub fn range(self) -> RangeInclusive<i64> ⓘ
pub fn range(self) -> RangeInclusive<i64> ⓘ
The values the type holds.
Sourcepub fn wider(self, other: Self) -> Self
pub fn wider(self, other: Self) -> Self
The type of an arithmetic operator’s result over the two types, the wider of them, as
int24pl returns an integer and int48mul a bigint.
Sourcepub fn value(self, value: i64) -> Result<CastValue, CastError>
pub fn value(self, value: i64) -> Result<CastValue, CastError>
The value held as the type, or the error a cast to the type raises for a value past its range.
§Errors
CastError::OutOfRange for a value outside IntegerType::range.
Trait Implementations§
Source§impl Clone for IntegerType
impl Clone for IntegerType
impl Copy for IntegerType
Source§impl Debug for IntegerType
impl Debug for IntegerType
impl Eq for IntegerType
Source§impl From<IntegerType> for BuiltinType
impl From<IntegerType> for BuiltinType
Source§fn from(integer: IntegerType) -> Self
fn from(integer: IntegerType) -> Self
Converts to this type from the input type.
Source§impl Hash for IntegerType
impl Hash for IntegerType
Source§impl Ord for IntegerType
impl Ord for IntegerType
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for IntegerType
impl PartialEq for IntegerType
Source§impl PartialOrd for IntegerType
impl PartialOrd for IntegerType
impl StructuralPartialEq for IntegerType
Source§impl TryFrom<BuiltinType> for IntegerType
Refuses a type that is not an integer type, returning it.
impl TryFrom<BuiltinType> for IntegerType
Refuses a type that is not an integer type, returning it.
Source§type Error = BuiltinType
type Error = BuiltinType
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Forget for IntegerType
impl Freeze for IntegerType
impl Move for IntegerType
impl RefUnwindSafe for IntegerType
impl Send for IntegerType
impl Sync for IntegerType
impl Unpin for IntegerType
impl UnsafeUnpin for IntegerType
impl UnwindSafe for IntegerType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more