#[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: i32Calendar months component.
days: i32Calendar days component.
micros: i64Microseconds component. DuckDB does not fold it into days:
INTERVAL '48 hours' has 0 days and 172,800,000,000 microseconds.
Implementations§
Source§impl DuckInterval
impl DuckInterval
Sourcepub fn to_micros(self) -> Option<i64>
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));Sourcepub fn to_micros_saturating(self) -> i64
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
impl Clone for DuckInterval
Source§fn clone(&self) -> DuckInterval
fn clone(&self) -> DuckInterval
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more