jbarrington429
jbarrington429

Reputation: 1

Rust Error failed to parse manifest no targets specified

I am learning Rust. This is the code I'm running

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());

This the error I receive. Any help would be greatly appreciated.

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

Upvotes: 0

Views: 779

Answers (1)

Zeppi
Zeppi

Reputation: 1235

Your code have some syntax errors, should be something like this

struct Object {
    width: u32,
    height:u32
}

impl Object {
    fn area(&self) -> u32 {
        self.width * self.height
    }

    fn new(width: u32, height: u32) -> Self {
        Self {
            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());
}

You can try it in playgound online https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1c4f18874d42608a35b7e825aaf19619

Or in your computer you run:

  1. cargo init atest
  2. cd atest
  3. [code, notepad, or your prefer editor] src/main.rs "update main.rs
  4. cargo run

Upvotes: 1

Related Questions