Skip to content

Commit 2931882

Browse files
committed
Box large jiff types
1 parent 967ecfa commit 2931882

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/value.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ pub enum Value {
280280

281281
#[cfg(feature = "with-jiff")]
282282
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
283-
JiffDateTime(Option<jiff::civil::DateTime>),
283+
JiffDateTime(Option<Box<jiff::civil::DateTime>>),
284284

285285
#[cfg(feature = "with-jiff")]
286286
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
287-
JiffTimestamp(Option<Timestamp>),
287+
JiffTimestamp(Option<Box<Timestamp>>),
288288

289289
#[cfg(feature = "with-jiff")]
290290
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
291-
JiffZoned(Option<Zoned>),
291+
JiffZoned(Option<Box<Zoned>>),
292292

293293
#[cfg(feature = "with-uuid")]
294294
#[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))]
@@ -326,8 +326,8 @@ pub enum Value {
326326
pub const VALUE_SIZE: usize = check_value_size();
327327

328328
const fn check_value_size() -> usize {
329-
if std::mem::size_of::<Value>() > 120 {
330-
panic!("the size of Value shouldn't be greater than 120 bytes")
329+
if std::mem::size_of::<Value>() > 32 {
330+
panic!("the size of Value shouldn't be greater than 32 bytes")
331331
}
332332
std::mem::size_of::<Value>()
333333
}
@@ -556,17 +556,19 @@ impl Value {
556556
#[cfg(feature = "with-jiff")]
557557
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
558558
Self::JiffDateTime(_) => {
559-
Self::JiffDateTime(Some(jiff::civil::date(1970, 1, 1).at(0, 0, 0, 0)))
559+
Self::JiffDateTime(Some(jiff::civil::date(1970, 1, 1).at(0, 0, 0, 0).into()))
560560
}
561561

562562
#[cfg(feature = "with-jiff")]
563563
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
564-
Self::JiffTimestamp(_) => Self::JiffTimestamp(Some(Timestamp::UNIX_EPOCH)),
564+
Self::JiffTimestamp(_) => Self::JiffTimestamp(Some(Timestamp::UNIX_EPOCH.into())),
565565

566566
#[cfg(feature = "with-jiff")]
567567
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
568568
Self::JiffZoned(_) => Self::JiffZoned(Some(
569-
Timestamp::UNIX_EPOCH.to_zoned(jiff::tz::TimeZone::UTC),
569+
Timestamp::UNIX_EPOCH
570+
.to_zoned(jiff::tz::TimeZone::UTC)
571+
.into(),
570572
)),
571573

572574
#[cfg(feature = "with-uuid")]
@@ -803,7 +805,7 @@ type_to_value!(char, Char, Char(None));
803805
type_to_value!(Vec<u8>, Bytes, VarBinary(StringLen::None));
804806
type_to_value!(String, String, String(StringLen::None));
805807

806-
#[cfg(feature = "with-bigdecimal")]
808+
#[cfg(any(feature = "with-bigdecimal", feature = "with-jiff"))]
807809
macro_rules! type_to_box_value {
808810
( $type: ty, $name: ident, $col_type: expr ) => {
809811
impl From<$type> for Value {
@@ -841,5 +843,6 @@ macro_rules! type_to_box_value {
841843
}
842844
};
843845
}
844-
#[cfg(feature = "with-bigdecimal")]
846+
847+
#[cfg(any(feature = "with-bigdecimal", feature = "with-jiff"))]
845848
use type_to_box_value;

src/value/with_jiff.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use jiff::{Timestamp, Zoned, civil};
33

44
type_to_value!(civil::Date, JiffDate, Date);
55
type_to_value!(civil::Time, JiffTime, Time);
6-
type_to_value!(civil::DateTime, JiffDateTime, DateTime);
7-
type_to_value!(Timestamp, JiffTimestamp, Timestamp);
8-
type_to_value!(Zoned, JiffZoned, TimestampWithTimeZone);
6+
type_to_box_value!(civil::DateTime, JiffDateTime, DateTime);
7+
type_to_box_value!(Timestamp, JiffTimestamp, Timestamp);
8+
type_to_box_value!(Zoned, JiffZoned, TimestampWithTimeZone);
99

1010
impl Value {
1111
#[inline]
@@ -20,17 +20,17 @@ impl Value {
2020

2121
#[inline]
2222
pub fn jiff_date_time<T: Into<Option<civil::DateTime>>>(v: T) -> Value {
23-
Value::JiffDateTime(v.into())
23+
Value::JiffDateTime(v.into().map(Into::into))
2424
}
2525

2626
#[inline]
2727
pub fn jiff_timestamp<T: Into<Option<Timestamp>>>(v: T) -> Value {
28-
Value::JiffTimestamp(v.into())
28+
Value::JiffTimestamp(v.into().map(Into::into))
2929
}
3030

3131
#[inline]
3232
pub fn jiff_zoned<T: Into<Option<Zoned>>>(v: T) -> Value {
33-
Value::JiffZoned(v.into())
33+
Value::JiffZoned(v.into().map(Into::into))
3434
}
3535
}
3636

@@ -71,21 +71,21 @@ impl Value {
7171

7272
pub fn as_ref_jiff_date_time(&self) -> Option<&civil::DateTime> {
7373
match self {
74-
Self::JiffDateTime(v) => v.as_ref(),
74+
Self::JiffDateTime(v) => v.as_deref(),
7575
_ => panic!("not Value::JiffDateTime"),
7676
}
7777
}
7878

7979
pub fn as_ref_jiff_timestamp(&self) -> Option<&Timestamp> {
8080
match self {
81-
Self::JiffTimestamp(v) => v.as_ref(),
81+
Self::JiffTimestamp(v) => v.as_deref(),
8282
_ => panic!("not Value::JiffTimestamp"),
8383
}
8484
}
8585

8686
pub fn as_ref_jiff_zoned(&self) -> Option<&Zoned> {
8787
match self {
88-
Self::JiffZoned(v) => v.as_ref(),
88+
Self::JiffZoned(v) => v.as_deref(),
8989
_ => panic!("not Value::JiffZoned"),
9090
}
9191
}

0 commit comments

Comments
 (0)