use std::fmt;
use std::str::FromStr;
use crate::error::ParseError;
use crate::fst_type::WeightType;
use crate::weight::Weight;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ErrorWeight {}
const NO_VALUES: &str = "ErrorWeight has no values; it exists only to name the \
arc type of an empty archive";
impl fmt::Display for ErrorWeight {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}
impl FromStr for ErrorWeight {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Err(ParseError::InvalidFormat(format!(
"cannot parse {s:?} as an error weight: {NO_VALUES}"
)))
}
}
impl Weight for ErrorWeight {
type ReverseWeight = ErrorWeight;
fn zero() -> Self {
panic!("{NO_VALUES}")
}
fn one() -> Self {
panic!("{NO_VALUES}")
}
fn no_weight() -> Self {
panic!("{NO_VALUES}")
}
fn type_name() -> WeightType {
WeightType::new("error")
}
fn properties() -> u64 {
0
}
fn plus(&self, _rhs: &Self) -> Self {
match *self {}
}
fn times(&self, _rhs: &Self) -> Self {
match *self {}
}
fn reverse(&self) -> Self::ReverseWeight {
match *self {}
}
fn is_member(&self) -> bool {
match *self {}
}
fn approx_equal(&self, _other: &Self, _delta: f32) -> bool {
match *self {}
}
fn quantize(&self, _delta: f32) -> Self {
match *self {}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_type_is_uninhabited() {
assert_eq!(size_of::<ErrorWeight>(), 0);
assert_eq!(size_of::<Option<ErrorWeight>>(), 0, "Option is too");
assert!(Vec::<ErrorWeight>::new().is_empty());
}
#[test]
fn it_names_itself_error_and_claims_no_properties() {
assert_eq!(ErrorWeight::type_name().as_str(), "error");
assert_eq!(ErrorWeight::properties(), 0);
}
#[test]
fn parsing_always_fails() {
assert!("".parse::<ErrorWeight>().is_err());
assert!("0".parse::<ErrorWeight>().is_err());
}
#[test]
#[should_panic(expected = "ErrorWeight has no values")]
#[allow(unreachable_code)]
fn zero_panics() {
let _ = ErrorWeight::zero();
}
#[test]
#[should_panic(expected = "ErrorWeight has no values")]
#[allow(unreachable_code)]
fn one_panics() {
let _ = ErrorWeight::one();
}
#[test]
#[should_panic(expected = "ErrorWeight has no values")]
#[allow(unreachable_code)]
fn no_weight_panics() {
let _ = ErrorWeight::no_weight();
}
}