Я пытаюсь вычислить простые числа в Rust, но у меня есть некоторые проблемы.Я получил две ошибки.Я не понимаю, как значение возвращается к основной функции.
fn main() {
let x = is_prime(25); //function calling
println!("{}", x);
}
fn is_prime(n: u32) -> bool {
let mut result: bool = for a in 2..n {
result = if n % a == 0 { false } else { true };
};
result
}
error[E0425]: cannot find value `result` in this scope
--> src/main.rs:8:9
|
8 | result = if n % a == 0 { false } else { true };
| ^^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
1 | use futures::future::result;
|
1 | use tokio::prelude::future::result;
|
error[E0308]: mismatched types
--> src/main.rs:7:28
|
6 | fn is_prime(n: u32) -> bool {
| ---- expected `bool` because of return type
7 | let mut result: bool = for a in 2..n {
| ____________________________^
8 | | result = if n % a == 0 { false } else { true };
9 | | };
| |_____^ expected bool, found ()
|
= note: expected type `bool`
found type `()`