Skip to content

I would like to know how to create struct and enum.. #3483

Closed
@ghost

Description

import io::*;

struct Point {x:float, y:float}

enum Shape{
    Circle(Point, float),
    Rectangle(Point, Point)
}

fn area(sh: Shape)->float{


    match sh{
        Circle(_,size)=>float::consts::pi*size*size,

        Rectangle(point1, point2)=>(point2.x-point1.x)*(point2.y-point1.y)
    }
}

fn main(){

    Circle{(4.5,5.5,),1.0};

    area(circle);

}

it doesn't work.. I'm a person who is using english as second language..
So there's a problem to understand document..

Please Let me know how to use it properly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions