【发布时间】:2021-10-23 17:15:33
【问题描述】:
我正在学习 Rust。这是我正在运行的代码
Struct Object {
width: u32,
height:u32,
}
impl Object {
fn area(&slef) --> u32 {
}
fn new(width: u32, height: u32) --> Object {
Object {
width,
height,
}
}
}
fn main() {
let o = Object {
width: 35,
height: 55,
};
let obj = Object ::new(57,83);
println!("{}x{} with area: {}", o.width, o.height, o.area());
println!("{}x{} with area: {}", obj.width, obj.height, obj.area());
这是我收到的错误。任何帮助将不胜感激。
PS C:\Users\Jessica\play_ground> cargo new play_ground --bin
warning: compiling this new package may not work due to invalid workspace configuration
failed to parse manifest at `C:\Users\Jessica\Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
Created binary (application) `play_ground` package
PS C:\Users\Jessica\play_ground> cargo run
error: failed to parse manifest at `C:\Users\Jessica\Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
PS C:\Users\Jessica\play_ground
【问题讨论】:
-
你的 rust 代码在
src/main.rs中吗?还是其他地方? -
再次查看您的终端输出,看起来
Cargo.toml在您的用户文件夹中,而它应该在play_ground/中 -
如果你的终端已经在
\play_ground目录下,那么你可能需要cargo new --bin .来代替
标签: rust rust-cargo