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-10863main
parent
18cb5e7b39
commit
ce48a654b1
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue