Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2022-03-16 14:14:42 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2022-03-16 14:16:28 -0400
commitce48a654b17deee9102a4e639cd331c3586e1264 (patch)
tree746f67ecf2ee948ba021e9f44ddbffbb34a36487 /tamer
parent18cb5e7b39f327156da47f4a99716e3da77ebf4c (diff)
downloadtame-ce48a654b17deee9102a4e639cd331c3586e1264.tar.gz
tame-ce48a654b17deee9102a4e639cd331c3586e1264.tar.bz2
tame-ce48a654b17deee9102a4e639cd331c3586e1264.zip
tamer: span::Span::offset_add: Make const
This behavior is unchanged, but it allows us to create more constant spans for testing. For example: const S = DUMMY_SPAN.offset_add(1).unwrap(); This, in turn, will allow for removing lazy_static! for tests that use it for span generation. DEV-10863
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/span.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/tamer/src/span.rs b/tamer/src/span.rs
index a0108d9..7fb1247 100644
--- a/tamer/src/span.rs
+++ b/tamer/src/span.rs
@@ -313,10 +313,14 @@ impl Span {
/// provided value.
/// If the resulting offset exceeds [`global::SourceFileSize`],
/// the result will be [`None`].
- pub fn offset_add(self, value: global::SourceFileSize) -> Option<Self> {
- self.offset
- .checked_add(value)
- .map(|offset| Self { offset, ..self })
+ pub const fn offset_add(
+ self,
+ value: global::SourceFileSize,
+ ) -> Option<Self> {
+ match self.offset.checked_add(value) {
+ Some(offset) => Some(Self { offset, ..self }),
+ None => None,
+ }
}
}