Use if cfg!() to dedup code

This commit is contained in:
René Kijewski 2024-01-11 15:34:29 +01:00 committed by René Kijewski
parent 3928e1df53
commit e493d3fef2

View File

@ -1201,21 +1201,15 @@ impl<'a> Generator<'a> {
Ok(DisplayWrap::Unwrapped)
}
#[cfg(not(feature = "serde-json"))]
fn _visit_json_filter(
&mut self,
_: &mut Buffer,
_: &[Expr<'_>],
) -> Result<DisplayWrap, CompileError> {
Err("the `json` filter requires the `serde-json` feature to be enabled".into())
}
#[cfg(feature = "serde-json")]
fn _visit_json_filter(
&mut self,
buf: &mut Buffer,
args: &[Expr<'_>],
) -> Result<DisplayWrap, CompileError> {
if cfg!(not(feature = "serde-json")) {
return Err("the `json` filter requires the `serde-json` feature to be enabled".into());
}
if args.len() != 1 {
return Err("unexpected argument(s) in `json` filter".into());
}