sota 0.7.0-rc4

API crate for Summits on the Air
Documentation
#![warn(missing_docs)]
//! sota-rs is a crate for interfacing with the Summits on the Air API.
pub mod alert;
pub mod assoc;
pub mod callsign;
pub mod client;
pub mod spot;
pub mod summit;

use std::{fmt::Display, hash::Hash, str::FromStr};

use serde::{de::DeserializeOwned, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};

pub use crate::{
    alert::Alert, callsign::Callsign, client::Client, spot::Spot, summit::Summit,
    summit::SummitRestriction,
};

/// A spot or alert.
#[allow(missing_docs)]
pub trait Notice: Hash + Eq + DeserializeOwned + Serialize {
    fn callsign(&self) -> &Callsign;
    fn timestamp(&self) -> String;
    fn epoch(&self) -> &str;
}

/// An item that stores a full summit code.
pub trait HasSummit {
    /// Return the full summit code, e.g. "W6/CC-063".
    fn summit_code(&self) -> String;
}

#[allow(clippy::upper_case_acronyms, missing_docs)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, SerializeDisplay, DeserializeFromStr)]
pub enum Mode {
    AM,
    CW,
    Data,
    DV,
    FM,
    SSB,
    Other,
}

impl FromStr for Mode {
    type Err = std::fmt::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let mode = match s.to_lowercase().as_ref() {
            "am" => Mode::AM,
            "cw" => Mode::CW,
            "data" => Mode::Data,
            "dv" => Mode::DV,
            "fm" => Mode::FM,
            "ssb" => Mode::SSB,
            _ => Mode::Other,
        };
        Ok(mode)
    }
}

impl Display for Mode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}