summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/util.rs
blob: 2b2069423b709dec6ebd303e6fd9e301d8ff17bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Copyright (c) 2020-2021 science+computing ag and other contributors
//
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//

use std::collections::HashMap;

use anyhow::Error;
use uuid::Uuid;

/// Get a `Display`able interface for a Map of errors
///
/// This is a helper trait for be able to display a `HashMap<Uuid, Error>`
/// in a `log::trace!()` call, for example
pub trait AsReceivedErrorDisplay {
    fn display_error_map(&self) -> ReceivedErrorDisplay<'_>;
}

impl AsReceivedErrorDisplay for HashMap<Uuid, Error> {
    fn display_error_map(&self) -> ReceivedErrorDisplay<'_> {
        ReceivedErrorDisplay(self)
    }
}


pub struct ReceivedErrorDisplay<'a>(&'a HashMap<Uuid, Error>);

impl<'a> std::fmt::Display for ReceivedErrorDisplay<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.iter().try_for_each(|(uuid, err)| writeln!(f, "{}: {}", uuid, err))
    }
}