//! Parsing of CfgFlags as command line arguments, as in
//!
//! rustc main.rs --cfg foo --cfg 'feature="bar"'
-use std::str::FromStr;
+use std::{fmt, str::FromStr};
use cfg::CfgOptions;
-use stdx::split_once;
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum CfgFlag {
impl FromStr for CfgFlag {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- let res = match split_once(s, '=') {
+ let res = match s.split_once('=') {
Some((key, value)) => {
if !(value.starts_with('"') && value.ends_with('"')) {
return Err(format!("Invalid cfg ({:?}), value should be in quotes", s));
}
}
}
+
+impl fmt::Display for CfgFlag {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ CfgFlag::Atom(atom) => f.write_str(atom),
+ CfgFlag::KeyValue { key, value } => {
+ f.write_str(key)?;
+ f.write_str("=")?;
+ f.write_str(value)
+ }
+ }
+ }
+}