public/subjects/format_me
miguel 1aa3484757 fix(rust-piscine) adding a new file for code editor to use 2023-11-14 18:09:37 +00:00
..
README.md feat(format_me): add new exercise for rust exams 2022-11-21 09:50:01 +00:00
main.rs fix(rust-piscine) adding a new file for code editor to use 2023-11-14 18:09:37 +00:00

README.md

format_me

Instructions

In this exercise you will implement the trait Display for the structure Park and the enum ParkType.

Here are the public fields and possible variants for the two types:

  • Park:
    • name as String
    • park_type as ParkType
    • address as String
    • cap as String
    • state as String
  • ParkType:
    • Garden
    • Forest
    • Playground

Expected Functions and Structures

use std::fmt;

pub struct Park {}
  
pub enum ParkType {}

impl fmt::Display for Park {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {}
}

impl fmt::Display for ParkType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {}
}

Usage

Here is a program to test your function:

use format_me::*;

fn main() {
    println!(
        "{}",
        Park {
            name: "Les Tuileries".to_string(),
            park_type: ParkType::Garden,
            address: "Pl. de la Concorde".to_string(),
            cap: "75001".to_string(),
            state: "France".to_string()
        }
    );
    println!(
        "{}",
        Park {
            name: "".to_string(),
            park_type: ParkType::Playground,
            address: "".to_string(),
            cap: "".to_string(),
            state: "".to_string()
        }
    );
}

And its output

$ cargo run
garden - Les Tuileries, Pl. de la Concorde, 75001 - France
playground - No name, No address, No cap - No state
$