It seems I can't call the method of the same struct in Rust or maybe I don't understand something:
struct St1 {
aa: String
}
impl St1 {
pub fn method1() -> String {
//....
method2() //error: unresolved name method2
}
pub fn method2() -> String {
//....
}
}
Is this how it's supposed to be?
You need to fully qualify the method you are calling.
struct St1 {
aa: String
}
impl St1 {
pub fn method1() -> String {
St1::method2()
}
pub fn method2() -> String {
unimplemented!()
}
}
On the off chance that you mean for these methods to be instance methods, then you still have to fully qualify them, but using self
instead:
struct St1 {
aa: String
}
impl St1 {
pub fn method1(&self) -> String {
self.method2()
}
pub fn method2(&self) -> String {
unimplemented!()
}
}
Note that Rust style is 4-space indents.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments