Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/tz/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,28 @@ impl TimeZone {
ARC_POSIX(_posix) => "POSIX",
}
}

/// Returns the heap memory usage, in bytes, of this timezone.
///
/// This does **not** include the stack size used up by this timezone.
/// To compute that, use `std::mem::size_of::<TimeZone>()`.
pub fn memory_usage(&self) -> usize {
repr::each! {
&self.repr,
UTC => 0,
UNKNOWN => 0,
FIXED(_offset) => 0,
STATIC_TZIF(_tzif) => 0,
ARC_TZIF(_tzif) => {
core::mem::size_of::<crate::tz::tzif::TzifOwned>() +
(core::mem::size_of::<core::sync::atomic::AtomicUsize>() * 2)
},
ARC_POSIX(_posix) => {
core::mem::size_of::<crate::tz::posix::PosixTimeZoneOwned>() +
(core::mem::size_of::<core::sync::atomic::AtomicUsize>() * 2)
},
}
}
}

// Exposed APIs for Jiff's time zone proc macro.
Expand Down
8 changes: 8 additions & 0 deletions src/zoned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,14 @@ impl Zoned {
let ZonedInner { timestamp, datetime, offset, time_zone } = inner;
(timestamp, datetime, offset, time_zone)
}

/// Returns the heap memory usage, in bytes, of this zoned.
///
/// This does **not** include the stack size used up by this zoned.
/// To compute that, use `std::mem::size_of::<Zoned>()`.
pub fn memory_usage(&self) -> usize {
self.inner.time_zone.memory_usage()
}
}

/// Parsing and formatting using a "printf"-style API.
Expand Down