Sha256: aa1fdadd31b43295b49c6d0d31dedf6ef2834a771b530b62e1f15cc15b5aa391

Contents?: true

Size: 661 Bytes

Versions: 157

Compression:

Stored size: 661 Bytes

Contents

use std::collections::HashMap;

pub struct School {
    grades: HashMap<u32, Vec<String>>
}

impl School {
    pub fn new() -> School {
        School { grades: HashMap::new() }
    }

    pub fn add(&mut self, grade: u32, student: &str) {
        let entry = self.grades.entry(grade).or_insert(Vec::new());
        entry.push(student.to_string());
        entry.sort();
    }

    pub fn grades(&self) -> Vec<u32> {
        let mut s = self.grades.keys().cloned().collect::<Vec<u32>>();
        s.sort();
        s
    }

    pub fn grade(&self, grade: u32) -> Option<Vec<String>> {
        self.grades.get(&grade).map(|v| v.iter().cloned().collect())
    }
}

Version data entries

157 entries across 157 versions & 1 rubygems

Version Path
trackler-2.2.1.179 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.178 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.177 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.176 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.175 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.174 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.173 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.172 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.171 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.170 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.169 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.167 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.166 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.165 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.164 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.163 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.162 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.161 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.160 tracks/rust/exercises/grade-school/example.rs
trackler-2.2.1.159 tracks/rust/exercises/grade-school/example.rs