为什么这个工作正常:
let items = [1, 2, 3];
let mut cumulator = 0;
for next in items.iter() {
cumulator += next;
}
println!("Final {}", cumulator);
Run Code Online (Sandbox Code Playgroud)
但这失败了?:
let items = [1, 2, 3];
let mut cumulator = 0;
for next in items.iter() {
cumulator += next.pow(2);
}
println!("Final {}", cumulator);
Run Code Online (Sandbox Code Playgroud)
错误.pow(2):
no method named `pow` found for reference `&{integer}` in the current scope
method not found in `&{integer}`rustc (E0599)
Run Code Online (Sandbox Code Playgroud)
我的 IDE 标识next为 i32,第一个代码示例工作正常。next.pow()但是当我引用或 上的任何函数时,编译器就会出现问题next。编译器抱怨这 …
我正在构建一个使用黄瓜的简单测试应用程序。不幸的是,当我尝试运行“ gradle cucumber ”时,它会抛出错误。然而,当我将 testImplement 更改为 build.gradle 中已弃用的 testCompile 时,一切运行正常。这是预期的行为吗?我需要做什么才能让 Cucumber 使用 testImplementation 运行?
构建.gradle:
dependencies {
testImplementation 'io.cucumber:cucumber-java:4.2.0'
testImplementation 'io.cucumber:cucumber-junit:4.2.0'
}
configurations {
cucumberRuntime {
extendsFrom testRuntime
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果(错误):
> Task :cucumber FAILED
Error: Could not find or load main class cucumber.api.cli.Main
Caused by: java.lang.ClassNotFoundException: cucumber.api.cli.Main
Run Code Online (Sandbox Code Playgroud)
构建.gradle: …
如何将 const 或 static 传递给 Rust 中的函数?
为什么这些不起作用?:
const COUNT: i32 = 5;
fn main() {
let repeated = "*".repeat(COUNT);
println!("Repeated Value: {}", repeated);
}
Run Code Online (Sandbox Code Playgroud)
和
static COUNT: i32 = 5;
fn main() {
let repeated = "*".repeat(COUNT);
println!("Repeated Value: {}", repeated);
}
Run Code Online (Sandbox Code Playgroud)
他们回来了:
mismatched types
expected `usize`, found `i32`
Run Code Online (Sandbox Code Playgroud)
但这些工作正常吗?:
fn main() {
let repeated = "*".repeat(5);
println!("Repeated Value: {}", repeated);
}
Run Code Online (Sandbox Code Playgroud)
和
fn main() {
let count = 5;
let repeated = "*".repeat(count);
println!("Repeated Value: {}", repeated);
} …Run Code Online (Sandbox Code Playgroud)