parse_env_filter/
eager.rs1extern crate alloc;
4
5use crate::{FieldFilter, ParseError};
6use alloc::vec::Vec;
7use core::convert::TryFrom;
8
9#[allow(clippy::result_unit_err)]
13pub fn filters(directives: &str) -> Result<Vec<Filter<'_>>, ParseError> {
14 crate::filters(directives)
15 .map(|filter| Filter::try_from(filter?))
16 .collect()
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct Filter<'a> {
22 pub target: &'a str,
23 pub span: Option<Vec<SpanFilter<'a>>>,
24 pub level: Option<&'a str>,
25}
26
27impl<'a> TryFrom<crate::Filter<'a>> for Filter<'a> {
28 type Error = ParseError;
29
30 fn try_from(filter: crate::Filter<'a>) -> Result<Self, Self::Error> {
31 Ok(Filter {
32 target: filter.target,
33 span: filter
34 .span
35 .map(|filters| {
36 filters
37 .map(|filter| SpanFilter::try_from(filter?))
38 .collect()
39 })
40 .transpose()?,
41 level: filter.level,
42 })
43 }
44}
45
46#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct SpanFilter<'a> {
49 pub name: &'a str,
50 pub fields: Option<Vec<FieldFilter<'a>>>,
51}
52
53impl<'a> TryFrom<crate::SpanFilter<'a>> for SpanFilter<'a> {
54 type Error = ParseError;
55
56 fn try_from(filter: crate::SpanFilter<'a>) -> Result<Self, Self::Error> {
57 Ok(SpanFilter {
58 name: filter.name,
59 fields: filter.fields.map(|filters| filters.collect()).transpose()?,
60 })
61 }
62}