kutil_http/headers/preferences/
preference.rs

1use super::{selector::*, weight::*};
2
3use std::fmt;
4
5//
6// Preference
7//
8
9/// Weighted preference.
10#[derive(Clone, Debug)]
11pub struct Preference<SelectionT> {
12    /// Selector.
13    pub selector: Selector<SelectionT>,
14
15    /// Weight.
16    pub weight: Weight,
17}
18
19impl<SelectionT> Preference<SelectionT> {
20    /// Constructor.
21    pub fn new(selector: Selector<SelectionT>, weight: Weight) -> Self {
22        Self { selector, weight }
23    }
24}
25
26impl<SelectionT> fmt::Display for Preference<SelectionT>
27where
28    SelectionT: fmt::Display,
29{
30    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self.weight {
32            Weight::MAX => fmt::Display::fmt(&self.selector, formatter),
33            weight => write!(formatter, "{};{}", self.selector, weight),
34        }
35    }
36}