#where is this function defined ?
42 messages · Page 1 of 1 (latest)
That's a Result, not Option. And you can search the standard library: https://doc.rust-lang.org/std/?search=is_ok
i mistyped
doesn't work
i cannot send screenshots
What do you mean doesn't work?
i did :
std::result::Result::is_ok
but doesn't work
fn main() {
let name : Result<i8, i8> = Ok(1);
println!("{}", name.std::result::Result::is_ok)
}
you can't call methods like that
how should i call it ?
Like you already had
what's wrong with the original code?
name.is_ok() is using it
i wanna add std::result::Result
what do you mean by "add"
why this instead of just name.is_ok()?
If you use rust enough, you'll learn how to understand it very quickly.
i need answer
You could do std::result::Result::is_ok(&name), but why? Why would ever do that?
@fringe salmon mate what about this
fn main() {
let start : Result<i8, i8> = Ok(1);
println!("{}", std::result::Result::is_ok_and(|a| a == 1))
}
???
how to refer to start ?
Okay, so what you're trying to do is directly call a method as a function. In Rust, methods are functions that have their first parameter as a self. This allows you to omit having to add arguments directly, but automatically putting the callee into the self parameter, i.e:
fn main() {
let start : Result<i8, i8> = Ok(1);
println!("{}", start.is_ok_and(|a| a == 1))
}
Is exactly equal to:
fn main() {
let start : Result<i8, i8> = Ok(1);
println!("{}", std::result::Result::is_ok_and(start, |a| a == 1))
}
What you've done does not work because you are not supplying the self parameter, which is normally inserted by the compiler when called as a method.
thanks man you are awesome
mate just one more question and i will go
Ok : is a variant
is_ok : is a method
right ?
yep
yahoo
As a rust beginner rust can be really confusing, but in the same time it's so amazing because it just makes sense