Skip to content

Commit

Permalink
Add TextSpan::from_str
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaput committed Jan 10, 2025
1 parent fa395d4 commit 3e41ca6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/cairo-lang-filesystem/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ pub struct TextSpan {
pub end: TextOffset,
}
impl TextSpan {
/// Creates a `TextSpan` for the entirety of a given string.
#[allow(clippy::should_implement_trait)]
pub fn from_str(content: &str) -> Self {
Self { start: TextOffset::START, end: TextOffset::from_str(content) }
}
pub fn width(self) -> TextWidth {
self.end - self.start
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-parser/src/db_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn test_token_stream_expr_parser() {
let token_stream = MockTokenStream {
tokens: vec![MockToken {
content: expr_code.to_string(),
span: TextSpan { start: TextOffset::default(), end: TextOffset::from_str(expr_code) },
span: TextSpan::from_str(expr_code),
}],
content_string: expr_code.to_string(),
};
Expand Down

0 comments on commit 3e41ca6

Please sign in to comment.