Something went wrong. Try again.
a TUI like cli tool to manage the features of your rust-project dependencies
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687use console::Emoji;use std::fmt::{Display, Formatter};
#[derive(Clone, Debug)]pub struct FeatureData { pub sub_features: Vec<SubFeature>, pub is_default: bool, pub enabled_state: EnabledState,}
#[derive(Clone, Debug, PartialEq)]pub enum EnabledState { Normal(bool), Workspace,}
impl FeatureData { pub fn is_enabled(&self) -> bool { match self.enabled_state { EnabledState::Normal(is_enabled) => is_enabled, EnabledState::Workspace => true, } }
pub fn is_toggleable(&self) -> bool { match self.enabled_state { EnabledState::Normal(_) => true, EnabledState::Workspace => false, } }
pub fn has_dependency_features(&self) -> bool { self.sub_features.iter().any(|feature| { matches!( feature.kind, SubFeatureType::Dependency | SubFeatureType::DependencyFeature ) }) }}
#[derive(Clone, Debug)]pub struct SubFeature { pub name: String, pub kind: SubFeatureType,}
/// https://doc.rust-lang.org/cargo/reference/features.html#[derive(Clone, PartialEq, Debug)]pub enum SubFeatureType { Normal, /// e.g. dep:gif Dependency, /// e.g. jpeg-decoder/rayon DependencyFeature,}
impl Display for SubFeature { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { if self.kind == SubFeatureType::Dependency { f.write_str(&format!( "{}{}", Emoji("📦", "dep:"), self.name.trim_start_matches("dep:") ))? } else { f.write_str(&self.name)? }
Ok(()) }}
impl From<&str> for SubFeatureType { fn from(s: &str) -> Self { if s.starts_with("dep:") { return SubFeatureType::Dependency; }
if s.contains('/') { return SubFeatureType::DependencyFeature; }
SubFeatureType::Normal }}