伙计们,我是 Rust 新手,我正在尝试在火车工具内进行递归,这是我的代码:
impl Solution {
pub fn some_fun() {
...
some_fun(); // Err: cannot find function `some_fun` in this scope not found in this scoperustcE0425
...
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何修复这个代码?
Ken*_*das 19
您正在定义 struct 的关联函数Solution。因此它属于Solution.
与 Java 等语言不同,Rust 不会神奇地解析当前类的一部分。您需要指定您尝试使用的东西的路径。在这种情况下,它会是这样的:
impl Solution {
pub fn some_fun() {
// ...
Solution::some_fun();
// ...
}
}
Run Code Online (Sandbox Code Playgroud)