borat/
lib.rs

1#![warn(clippy::all, clippy::pedantic, clippy::unwrap_used)]
2
3use colored::Colorize;
4use serde::Deserialize;
5
6const OPEN_SYMBOL: &str = "✓";
7const CLOSED_SYMBOL: &str = "✗";
8
9/// A representation of a breakout room, including its English name and
10/// current status.
11#[derive(Debug, Deserialize)]
12pub struct BreakoutRoomInfo {
13    pub name: String,
14    pub open: bool,
15}
16
17impl std::fmt::Display for BreakoutRoomInfo {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        let symbol = if self.open {
20            OPEN_SYMBOL.green()
21        } else {
22            CLOSED_SYMBOL.red()
23        };
24        write!(f, " {} {}", symbol, self.name)
25    }
26}
27
28/// Represents the ways in which a call to the Borat API can fail.
29#[derive(Debug)]
30pub enum BoratError {
31    NetworkError(String),
32    ParseError(String),
33}
34
35impl std::fmt::Display for BoratError {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        match self {
38            BoratError::NetworkError(url) => write!(
39                f,
40                "A network error occurred while trying to fetch data from '{url}'."
41            ),
42            BoratError::ParseError(url) => write!(f, "Could not parse API response from '{url}'."),
43        }
44    }
45}
46
47impl std::error::Error for BoratError {}