Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Jan 25, 2022
1 parent 4f34022 commit 3bf397a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/filters/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl Filter for Capture {
#[cfg_attr(feature = "instrument", tracing::instrument(skip(self, ctx)))]
fn read(&self, mut ctx: ReadContext) -> Option<ReadResponse> {
let capture = self.capture.capture(&mut ctx.contents, &self.metrics);
ctx.metadata.insert(self.is_present_key.clone(), Value::Bool(capture.is_some()));
ctx.metadata
.insert(self.is_present_key.clone(), Value::Bool(capture.is_some()));

if let Some(value) = capture {
ctx.metadata.insert(self.metadata_key.clone(), value);
Expand Down
29 changes: 20 additions & 9 deletions src/filters/capture/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ impl Serialize for Config {
impl<'de> serde::Deserialize<'de> for Config {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(field_identifier, rename_all = "lowercase")]
enum Field {
#[serde(rename="metadataKey")]
#[serde(rename = "metadataKey")]
MetadataKey,
Prefix,
Suffix,
Expand All @@ -103,37 +103,41 @@ impl<'de> serde::Deserialize<'de> for Config {
{
let mut metadata_key = None;
let mut strategy = None;
let strategy_exists_err = || Err(serde::de::Error::custom("Multiple strategies found, only one capture strategy is permitted"));
let strategy_exists_err = || {
Err(serde::de::Error::custom(
"Multiple strategies found, only one capture strategy is permitted",
))
};

while let Some(key) = map.next_key()? {
match key {
Field::MetadataKey => {
if metadata_key.is_some() {
return Err(serde::de::Error::duplicate_field("metadataKey"))
return Err(serde::de::Error::duplicate_field("metadataKey"));
}

metadata_key = Some(map.next_value()?);
}

Field::Prefix => {
if strategy.is_some() {
return (strategy_exists_err)()
return (strategy_exists_err)();
}

strategy = Some(Strategy::Prefix(map.next_value()?));
}

Field::Suffix => {
if strategy.is_some() {
return (strategy_exists_err)()
return (strategy_exists_err)();
}

strategy = Some(Strategy::Suffix(map.next_value()?));
}

Field::Regex => {
if strategy.is_some() {
return (strategy_exists_err)()
return (strategy_exists_err)();
}

strategy = Some(Strategy::Regex(map.next_value()?));
Expand All @@ -142,9 +146,16 @@ impl<'de> serde::Deserialize<'de> for Config {
}

let metadata_key = metadata_key.unwrap_or_else(|| CAPTURED_BYTES.into());
let strategy = strategy.ok_or_else(|| serde::de::Error::custom("Capture strategy of `regex`, `suffix`, or `prefix` is required"))?;
let strategy = strategy.ok_or_else(|| {
serde::de::Error::custom(
"Capture strategy of `regex`, `suffix`, or `prefix` is required",
)
})?;

Ok(Config { metadata_key, strategy })
Ok(Config {
metadata_key,
strategy,
})
}
}

Expand Down

0 comments on commit 3bf397a

Please sign in to comment.