Snippets

Eric Young Iterator filtering fun

Created by Eric Young last modified
pub fn get_filtered_players(&self, name: Option<String>, uuid: Option<String>, whitelisted: Option<bool>, op: Option<bool>, online: Option<bool>) -> Vec<&MinecraftPlayer> {
        self.players.values().filter(|&player| {
            match name.as_ref() {
                Some(name) => name.to_lowercase() == player.name,
                None => true
            }
        }).filter(|&player| {
            match uuid.as_ref() {
                Some(uuid) => uuid == &player.uuid,
                None => true
            }
        }).filter(|&player| {
            match whitelisted {
                Some(whitelisted) => whitelisted == player.white_listed,
                None => true
            }
        }).filter(|&player| {
            match op {
                Some(op) => op == player.op,
                None => true
            }
        }).filter(|&player| {
            match online {
                Some(online) => online == player.online,
                None => true
            }
        }).collect()
    }

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.