Skip to main content

DuckInterval

Struct DuckInterval 

Source
#[repr(C)]
pub struct DuckInterval { pub months: i32, pub days: i32, pub micros: i64, }
Expand description

A DuckDB INTERVAL value, matching the C struct layout exactly.

§Memory layout

offset 0:  months (i32)  — number of calendar months
offset 4:  days   (i32)  — number of calendar days
offset 8:  micros (i64)  — microseconds component
total:     16 bytes

§Equality is field-by-field, not SQL equality

The derived PartialEq, Eq and Hash compare the three fields, so { months: 1, .. } and { days: 30, .. } are different values here while DuckDB says interval '1 month' = interval '30 days'. Comparing to_micros matches SQL when the three fields share a sign; see interval_to_micros for the mixed-sign case where it does not.

§Safety

This struct must remain #[repr(C)] with the exact field order above, matching DuckDB’s duckdb_interval C struct.

Fields§

§months: i32

Calendar months component.

§days: i32

Calendar days component.

§micros: i64

Microseconds component. DuckDB does not fold it into days: INTERVAL '48 hours' has 0 days and 172,800,000,000 microseconds.

Implementations§

Source§

impl DuckInterval

Source

pub const fn zero() -> Self

Returns a zero-valued interval (0 months, 0 days, 0 microseconds).

Source

pub fn to_micros(self) -> Option<i64>

Converts this interval to total microseconds with overflow checking.

Returns None if the result would overflow i64.

Month conversion uses 30 days/month; see interval_to_micros for where that matches DuckDB and where it does not.

§Example
use quack_rs::interval::DuckInterval;

let iv = DuckInterval { months: 0, days: 1, micros: 500_000 };
assert_eq!(iv.to_micros(), Some(86_400_500_000_i64));
Source

pub fn to_micros_saturating(self) -> i64

Converts this interval to total microseconds, saturating on overflow.

§Example
use quack_rs::interval::DuckInterval;

let iv = DuckInterval { months: i32::MAX, days: i32::MAX, micros: i64::MAX };
assert_eq!(iv.to_micros_saturating(), i64::MAX);

Trait Implementations§

Source§

impl Clone for DuckInterval

Source§

fn clone(&self) -> DuckInterval

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DuckInterval

Source§

impl Debug for DuckInterval

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DuckInterval

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DuckInterval

Source§

impl Hash for DuckInterval

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DuckInterval

Source§

fn eq(&self, other: &DuckInterval) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DuckInterval

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.