简体   繁体   English

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

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

Guys, I am new to rust, and I am tring to do recursion inside a Train Implement, Here is My code:伙计们,我是 rust 的新手,我正在尝试在火车工具中进行递归,这是我的代码:

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 .您正在为 struct Solution定义关联的 function 。 Therefore it is scoped under Solution .因此,它的范围在Solution下。

Unlike languages like Java, Rust does not magically resolve things that are part of the current class.与 Java 之类的语言不同,Rust 不会神奇地解决当前 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();
     // ...
   }
}

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

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