Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find function in this scope not found in this scope in Rust

Tags:

rust

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 ?

like image 389
En Xie Avatar asked Dec 15 '25 11:12

En Xie


1 Answers

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();
     // ...
   }
}
like image 82
Kendas Avatar answered Dec 17 '25 00:12

Kendas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!