繁体   English   中英

在此 scope 中找不到 function 在此 scope 中未找到 ZF5E265D607CB720858FC166E8Z

[英]cannot find function in this scope not found in this scope in Rust

伙计们,我是 rust 的新手,我正在尝试在火车工具中进行递归,这是我的代码:

impl Solution {
   pub fn some_fun() {
     ...
     some_fun(); // Err: cannot find function `some_fun` in this scope not found in this scoperustcE0425
     ...
   }
}

如何修复此代码?

您正在为 struct Solution定义关联的 function 。 因此,它的范围在Solution下。

与 Java 之类的语言不同,Rust 不会神奇地解决当前 class 中的问题。 您需要指定您尝试使用的东西的路径。 在这种情况下,它将类似于:

impl Solution {
   pub fn some_fun() {
     // ...
     Solution::some_fun();
     // ...
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM