From aec15591f3a6dafc685af97296f9d78c0cdfd9bd Mon Sep 17 00:00:00 2001 From: 0xLucqs <70894690+0xLucqs@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:46:05 +0200 Subject: [PATCH] feat(span): add to_str_range for `TextSpan` (#6122) --- crates/cairo-lang-filesystem/src/span.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/cairo-lang-filesystem/src/span.rs b/crates/cairo-lang-filesystem/src/span.rs index 38244d9c456..de4d2bc42fc 100644 --- a/crates/cairo-lang-filesystem/src/span.rs +++ b/crates/cairo-lang-filesystem/src/span.rs @@ -1,5 +1,5 @@ use std::iter::Sum; -use std::ops::{Add, Sub}; +use std::ops::{Add, Range, Sub}; use crate::db::FilesGroup; use crate::ids::FileId; @@ -94,6 +94,11 @@ impl TextSpan { Self { start: self.start, end: self.start } } + /// Returns self.start..self.end as [`Range`] + pub fn to_str_range(&self) -> Range { + self.start.0.0 as usize..self.end.0.0 as usize + } + /// Convert this span to a [`TextPositionSpan`] in the file. pub fn position_in_file(self, db: &dyn FilesGroup, file: FileId) -> Option { let start = self.start.position_in_file(db, file)?;