so i have got two files main.rs and utils.rs
I implemented StringUtils method on utils.rs but when I try to use the method in main.rs it gives me this error
error[E0599]: no method named `slice` found for reference `&str` in the current scope --> src\main.rs:89:50 | 89 | let text: String = self.inner.clone().as_str().slice(self.start, self.current); | ^^^^^ method not found in `&str` | = help: items from traits can only be used if the trait is implemented and in scope note: `StringUtils` defines an item `slice`, perhaps you need to implement it --> src\util.rs:25:1 | 25 | trait StringUtils { | ^^^^^^^^^^^^^^^^^
// main.rs
mod utils;
use utils::*;
...
fn add_token0(&mut self, token_type: TokenType) {
let text: String = self.inner.clone().as_str().slice(self.start, self.current);
// error: no method named `slice` found for reference `&str` in the current scope
}
...
but I implemented it already on utils.rs
// utils.rs
...
trait StringUtils {
...
fn slice(&self, range: impl RangeBounds<usize>) -> &str;
...
}
impl StringUtils for str {
...
fn slice(&self, range: impl RangeBounds<usize>) -> &str {
...
}
...
}
...
why doesn't my implementation work, and is there any way to solve it or I can only implement StringUtils on main.rs?