Skip to content

Commit

Permalink
fix: Remove once_cell dependency from derive
Browse files Browse the repository at this point in the history
With being able to accept owned types now, `clap_derive` no longer needs
`once_cell` to make dynamic data static.

This helps towards clap-rs#1365, clap-rs#2037
  • Loading branch information
epage committed Aug 16, 2022
1 parent 91e55c6 commit 429143a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -69,7 +69,7 @@ suggestions = ["dep:strsim"]

# Optional
deprecated = ["clap_derive?/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
derive = ["clap_derive", "dep:once_cell"]
derive = ["clap_derive"]
cargo = ["dep:once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
wrap_help = ["dep:terminal_size", "textwrap/terminal_size"]
env = [] # Use environment variables during arg parsing
Expand Down
38 changes: 8 additions & 30 deletions clap_derive/src/attrs.rs
Expand Up @@ -504,11 +504,10 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<String> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
{
let val: #ty = #val;
::std::string::ToString::to_string(&val)
});
&*DEFAULT_VALUE
}
})
};

Expand Down Expand Up @@ -558,10 +557,7 @@ impl Attrs {

}

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
} else {
Expand All @@ -575,14 +571,7 @@ impl Attrs {

}

static DEFAULT_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
};
Expand Down Expand Up @@ -619,11 +608,10 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
{
let val: #ty = #val;
::std::ffi::OsString::from(val)
});
&*DEFAULT_VALUE
}
})
};

Expand Down Expand Up @@ -674,10 +662,7 @@ impl Attrs {

}

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
} else {
Expand All @@ -691,14 +676,7 @@ impl Attrs {

}

static DEFAULT_OS_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -131,7 +131,7 @@ pub mod _tutorial;

#[doc(hidden)]
pub mod __macro_refs {
#[cfg(any(feature = "derive", feature = "cargo"))]
#[cfg(feature = "cargo")]
#[doc(hidden)]
pub use once_cell;
}
Expand Down

0 comments on commit 429143a

Please sign in to comment.