#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub enum FeatureGroupChoice
{
ethtool_sg,
ethtool_tx,
ethtool_txvlan,
ethtool_rxvlan,
ethtool_gso,
ethtool_gro,
ethtool_lro,
ethtool_tso,
ethtool_ntuple,
ethtool_rxhash,
ethtool_rx,
internet_protocols_checksum,
internet_protocols_checksum_in_hardware,
generic_send_offload_encapsulation,
OtherToEnable(FeatureGroup),
OtherToDisable(FeatureGroup),
}
impl Debug for FeatureGroupChoice
{
#[inline(always)]
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "FeatureGroupChoice")
}
}
impl Clone for FeatureGroupChoice
{
#[inline(always)]
fn clone(&self) -> Self
{
use self::FeatureGroupChoice::*;
match self
{
ðtool_sg => ethtool_sg,
ðtool_tx => ethtool_tx,
ðtool_txvlan => ethtool_txvlan,
ðtool_rxvlan => ethtool_rxvlan,
ðtool_gso => ethtool_gso,
ðtool_gro => ethtool_gro,
ðtool_lro => ethtool_lro,
ðtool_tso => ethtool_tso,
ðtool_ntuple => ethtool_ntuple,
ðtool_rxhash => ethtool_rxhash,
ðtool_rx => ethtool_rx,
&internet_protocols_checksum => internet_protocols_checksum,
&internet_protocols_checksum_in_hardware => internet_protocols_checksum_in_hardware,
&generic_send_offload_encapsulation => generic_send_offload_encapsulation,
&OtherToEnable(ref feature_group) => OtherToEnable(feature_group.clone()),
&OtherToDisable(ref feature_group) => OtherToDisable(feature_group.clone()),
}
}
}
impl PartialEq for FeatureGroupChoice
{
#[inline(always)]
fn eq(&self, other: &Self) -> bool
{
use self::FeatureGroupChoice::*;
match (self, other)
{
(ðtool_sg, ðtool_sg) => true,
(ðtool_tx, ðtool_tx) => true,
(ðtool_txvlan, ðtool_txvlan) => true,
(ðtool_rxvlan, ðtool_rxvlan) => true,
(ðtool_gso, ðtool_gso) => true,
(ðtool_gro, ðtool_gro) => true,
(ðtool_lro, ðtool_lro) => true,
(ðtool_tso, ðtool_tso) => true,
(ðtool_ntuple, ðtool_ntuple) => true,
(ðtool_rxhash, ðtool_rxhash) => true,
(ðtool_rx, ðtool_rx) => true,
(&internet_protocols_checksum, &internet_protocols_checksum) => true,
(&internet_protocols_checksum_in_hardware, &internet_protocols_checksum_in_hardware) => true,
(&generic_send_offload_encapsulation, &generic_send_offload_encapsulation) => true,
(&OtherToEnable(ref left_feature_group), &OtherToEnable(ref right_feature_group)) => left_feature_group.eq(right_feature_group),
(&OtherToDisable(ref left_feature_group), &OtherToDisable(ref right_feature_group)) => left_feature_group.eq(right_feature_group),
_ => false,
}
}
}
impl Eq for FeatureGroupChoice
{
}
impl<'a> Sub<Feature> for &'a FeatureGroupChoice
{
type Output = FeatureGroupChoice;
#[inline(always)]
fn sub(self, rhs: Feature) -> Self::Output
{
use self::FeatureGroupChoice::*;
#[inline(always)]
fn non_static_lifetime(feature_group: &FeatureGroup, feature: &Feature, enable: bool) -> FeatureGroupChoice
{
let mut hash_set = feature_group.0.clone();
hash_set.remove(feature);
let feature_group = FeatureGroup::from(hash_set);
if enable
{
OtherToEnable(feature_group)
}
else
{
OtherToDisable(feature_group)
}
}
let feature_group = match &self
{
ðtool_sg => FeatureGroup::ethtool_sg(),
ðtool_tx => FeatureGroup::ethtool_tx(),
ðtool_txvlan => FeatureGroup::ethtool_txvlan(),
ðtool_rxvlan => FeatureGroup::ethtool_rxvlan(),
ðtool_gso => FeatureGroup::ethtool_gso(),
ðtool_gro => FeatureGroup::ethtool_gro(),
ðtool_lro => FeatureGroup::ethtool_lro(),
ðtool_tso => FeatureGroup::ethtool_tso(),
ðtool_ntuple => FeatureGroup::ethtool_ntuple(),
ðtool_rxhash => FeatureGroup::ethtool_rxhash(),
ðtool_rx => FeatureGroup::ethtool_rx(),
&internet_protocols_checksum => FeatureGroup::internet_protocols_checksum(),
&internet_protocols_checksum_in_hardware => FeatureGroup::internet_protocols_checksum_in_hardware(),
&generic_send_offload_encapsulation => FeatureGroup::generic_send_offload_encapsulation(),
&OtherToEnable(ref feature_group) => return non_static_lifetime(feature_group, &rhs, true),
&OtherToDisable(ref feature_group) => return non_static_lifetime(feature_group, &rhs, false),
};
if feature_group.contains(&rhs)
{
let mut hash_set = feature_group.0.clone();
hash_set.remove(&rhs);
OtherToEnable(FeatureGroup::from(hash_set))
}
else
{
self.clone()
}
}
}
impl Sub<Feature> for FeatureGroupChoice
{
type Output = Self;
#[inline(always)]
fn sub(self, rhs: Feature) -> Self::Output
{
(&self) - rhs
}
}
impl FeatureGroupChoice
{
#[inline(always)]
pub fn enable_one(feature: Feature) -> Self
{
Self::enable(fast_secure_hash_set! [feature])
}
#[inline(always)]
pub fn enable(features: HashSet<Feature>) -> Self
{
FeatureGroupChoice::OtherToEnable(FeatureGroup::from(features))
}
#[inline(always)]
pub fn disable_one(feature: Feature) -> Self
{
Self::disable(fast_secure_hash_set! [feature])
}
#[inline(always)]
pub fn disable(features: HashSet<Feature>) -> Self
{
FeatureGroupChoice::OtherToDisable(FeatureGroup::from(features))
}
#[inline(always)]
pub(crate) fn iter(feature_group_choices: &Vec<Self>) -> impl Iterator<Item=HashMap<Feature, bool>> + '_
{
feature_group_choices.iter().map(|feature_group_choice| feature_group_choice.to_feature_settings())
}
#[inline(always)]
pub(crate) fn to_feature_settings(&self) -> HashMap<Feature, bool>
{
use self::FeatureGroupChoice::*;
match self
{
ethtool_sg => FeatureGroup::ethtool_sg().enable(),
ethtool_tx => FeatureGroup::ethtool_tx().enable(),
ethtool_txvlan => FeatureGroup::ethtool_txvlan().enable(),
ethtool_rxvlan => FeatureGroup::ethtool_rxvlan().enable(),
ethtool_gso => FeatureGroup::ethtool_gso().enable(),
ethtool_gro => FeatureGroup::ethtool_gro().enable(),
ethtool_lro => FeatureGroup::ethtool_lro().enable(),
ethtool_tso => FeatureGroup::ethtool_tso().enable(),
ethtool_ntuple => FeatureGroup::ethtool_ntuple().enable(),
ethtool_rxhash => FeatureGroup::ethtool_rxhash().enable(),
ethtool_rx => FeatureGroup::ethtool_rx().enable(),
internet_protocols_checksum => FeatureGroup::internet_protocols_checksum().enable(),
internet_protocols_checksum_in_hardware => FeatureGroup::internet_protocols_checksum_in_hardware().enable(),
generic_send_offload_encapsulation => FeatureGroup::generic_send_offload_encapsulation().enable(),
OtherToEnable(ref feature_group) => feature_group.enable(),
OtherToDisable(ref feature_group) => feature_group.disable(),
}
}
}