diff --git a/src/regex/bytes.rs b/src/regex/bytes.rs index 7b7aad574..275d0e2db 100644 --- a/src/regex/bytes.rs +++ b/src/regex/bytes.rs @@ -1429,6 +1429,15 @@ impl Regex { pub fn locations(&self) -> CaptureLocations { self.capture_locations() } + + /// Returns the memory usage, in bytes, of this `Regex`. + /// + /// This does **not** include the stack size used up by this `Regex`. + /// To compute that, use `std::mem::size_of::()`. + #[inline] + pub fn memory_usage(&self) -> usize { + self.meta.memory_usage() + } } /// Represents a single match of a regex in a haystack. diff --git a/src/regex/string.rs b/src/regex/string.rs index dba94d46e..10fd3adf7 100644 --- a/src/regex/string.rs +++ b/src/regex/string.rs @@ -1432,6 +1432,15 @@ impl Regex { pub fn locations(&self) -> CaptureLocations { self.capture_locations() } + + /// Returns the memory usage, in bytes, of this `Regex`. + /// + /// This does **not** include the stack size used up by this `Regex`. + /// To compute that, use `std::mem::size_of::()`. + #[inline] + pub fn memory_usage(&self) -> usize { + self.meta.memory_usage() + } } /// Represents a single match of a regex in a haystack.