Guys, I am new to rust, and I am tring to do recursion inside a Train Implement, Here is My code:
impl Solution {
pub fn some_fun() {
...
some_fun(); // Err: cannot find function `some_fun` in this scope not found in this scoperustcE0425
...
}
}
how can I fix this code ?
You are defining an associated function to the struct Solution. Therefore it is scoped under Solution.
Unlike languages like Java, Rust does not magically resolve things that are part of the current class. You need to specify the path to the thing you are attempting to use. In this case, it would be something like:
impl Solution {
pub fn some_fun() {
// ...
Solution::some_fun();
// ...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With