pub struct PrimitiveScalar<'a> { /* private fields */ }Expand description
A scalar value representing a primitive type.
This type provides a view into a primitive scalar value of any primitive type (integers, floats) with various bit widths.
Implementations§
Source§impl<'a> PrimitiveScalar<'a>
impl<'a> PrimitiveScalar<'a>
Sourcepub fn try_new(dtype: &'a DType, value: &ScalarValue) -> VortexResult<Self>
pub fn try_new(dtype: &'a DType, value: &ScalarValue) -> VortexResult<Self>
Creates a new primitive scalar from a data type and scalar value.
§Errors
Returns an error if the data type is not a primitive type or if the value cannot be converted to the expected primitive type.
Sourcepub fn typed_value<T: NativePType>(&self) -> Option<T>
pub fn typed_value<T: NativePType>(&self) -> Option<T>
Returns the value as a specific native primitive type.
Returns None if the scalar is null, otherwise returns Some(value) where
value is the underlying primitive value cast to the requested type T.
§Panics
Panics if the primitive type of this scalar does not match the requested type.
Sourcepub fn as_<T: FromPrimitiveOrF16>(&self) -> Option<T>
pub fn as_<T: FromPrimitiveOrF16>(&self) -> Option<T>
Attempts to extract the primitive value as the given type.
§Errors
Panics if the cast fails due to overflow or type incompatibility. See also
as_opt for the checked version that does not panic.
§Examples
let wide = Scalar::primitive(1000i32, false.into());
// This succeeds
let narrow = wide.as_primitive().as_::<i16>();
assert_eq!(narrow, Some(1000i16));
// This also succeeds
let null = Scalar::null(DType::Primitive(PType::I16, true.into()));
assert_eq!(null.as_primitive().as_::<i8>(), None);
// This will panic, because 1000 does not fit in i8
wide.as_primitive().as_::<i8>();Sourcepub fn as_opt<T: FromPrimitiveOrF16>(&self) -> Option<Option<T>>
pub fn as_opt<T: FromPrimitiveOrF16>(&self) -> Option<Option<T>>
Returns the inner value cast to the desired type.
If the cast fails, None is returned. If the scalar represents a null, Some(None)
is returned. Otherwise, Some(Some(T)) is returned for a successful non-null conversion.
§Examples
// Non-null values
let scalar = Scalar::primitive(100i32, false.into());
let primitive = scalar.as_primitive();
assert_eq!(primitive.as_opt::<i8>(), Some(Some(100i8)));
// Null value
let scalar = Scalar::null(DType::Primitive(PType::I32, true.into()));
let primitive = scalar.as_primitive();
assert_eq!(primitive.as_opt::<i8>(), Some(None));
// Failed conversion: 1000 cannot fit in an i8
let scalar = Scalar::primitive(1000i32, false.into());
let primitive = scalar.as_primitive();
assert_eq!(primitive.as_opt::<i8>(), None);Source§impl<'a> PrimitiveScalar<'a>
impl<'a> PrimitiveScalar<'a>
Sourcepub fn checked_binary_numeric(
&self,
other: &PrimitiveScalar<'a>,
op: NumericOperator,
) -> Option<PrimitiveScalar<'a>>
pub fn checked_binary_numeric( &self, other: &PrimitiveScalar<'a>, op: NumericOperator, ) -> Option<PrimitiveScalar<'a>>
Apply the (checked) operator to self and other using SQL-style null semantics.
If the operation overflows, Ok(None) is returned.
If the types are incompatible (ignoring nullability), an error is returned.
If either value is null, the result is null.
Trait Implementations§
Source§impl Add for PrimitiveScalar<'_>
impl Add for PrimitiveScalar<'_>
Source§impl CheckedAdd for PrimitiveScalar<'_>
impl CheckedAdd for PrimitiveScalar<'_>
Source§fn checked_add(&self, rhs: &Self) -> Option<Self>
fn checked_add(&self, rhs: &Self) -> Option<Self>
None is
returned.Source§impl CheckedSub for PrimitiveScalar<'_>
impl CheckedSub for PrimitiveScalar<'_>
Source§fn checked_sub(&self, rhs: &Self) -> Option<Self>
fn checked_sub(&self, rhs: &Self) -> Option<Self>
None is returned.Source§impl<'a> Clone for PrimitiveScalar<'a>
impl<'a> Clone for PrimitiveScalar<'a>
Source§fn clone(&self) -> PrimitiveScalar<'a>
fn clone(&self) -> PrimitiveScalar<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for PrimitiveScalar<'a>
impl<'a> Debug for PrimitiveScalar<'a>
Source§impl Display for PrimitiveScalar<'_>
impl Display for PrimitiveScalar<'_>
Source§impl From<PrimitiveScalar<'_>> for Scalar
impl From<PrimitiveScalar<'_>> for Scalar
Source§fn from(pscalar: PrimitiveScalar<'_>) -> Self
fn from(pscalar: PrimitiveScalar<'_>) -> Self
Source§impl<'a> Hash for PrimitiveScalar<'a>
impl<'a> Hash for PrimitiveScalar<'a>
Source§impl PartialEq for PrimitiveScalar<'_>
impl PartialEq for PrimitiveScalar<'_>
Source§impl PartialOrd for PrimitiveScalar<'_>
Ord is not implemented since it’s undefined for different PTypes
impl PartialOrd for PrimitiveScalar<'_>
Ord is not implemented since it’s undefined for different PTypes
Source§impl Sub for PrimitiveScalar<'_>
impl Sub for PrimitiveScalar<'_>
Source§impl<'a> TryFrom<&'a Scalar> for PrimitiveScalar<'a>
impl<'a> TryFrom<&'a Scalar> for PrimitiveScalar<'a>
impl<'a> Copy for PrimitiveScalar<'a>
impl Eq for PrimitiveScalar<'_>
Auto Trait Implementations§
impl<'a> Freeze for PrimitiveScalar<'a>
impl<'a> RefUnwindSafe for PrimitiveScalar<'a>
impl<'a> Send for PrimitiveScalar<'a>
impl<'a> Sync for PrimitiveScalar<'a>
impl<'a> Unpin for PrimitiveScalar<'a>
impl<'a> UnwindSafe for PrimitiveScalar<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.