<commit_before>use std::marker::PhantomData;
use std::ops::Deref;
use std::str::FromStr;

use glob::Pattern;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Unexpected, Visitor};

#[derive(Clone)]
pub struct Globber(pub Pattern);

impl Serialize for Globber {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where S: Serializer
  {
    serializer.serialize_str(self.as_str())
  }
}

impl Deserialize for Globber {
  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where D: Deserializer
  {
    struct VariantVisitor<__D> {
      _marker: PhantomData<__D>,
    }

    impl<__D> Visitor for VariantVisitor<__D>
      where __D: Deserializer
    {
      type Value = Globber;

      fn visit_str<E>(self, value: &str) -> Result<Globber, E>
        where E: ::serde::de::Error
      {
        Pattern::from_str(value)
          .map(|p| Globber(p))
          .map_err(|_| E::invalid_value(Unexpected::Str(value), &self))
      }

      fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        formatter.write_str("a valid file path glob expression")
      }
    }

    deserializer.deserialize_str(VariantVisitor::<D> { _marker: PhantomData, })
  }
}

impl FromStr for Globber {
  type Err = <Pattern as FromStr>::Err;

  fn from_str(s: &str) -> Result<Self, Self::Err> {
    Pattern::from_str(s).map(|p| Globber(p))
  }
}

impl Deref for Globber {
  type Target = Pattern;
  fn deref(&self) -> &Self::Target {
    &self.0
  }
}<commit_msg>Rely on Globber's FromStr impl.<commit_after>use std::marker::PhantomData;
use std::ops::Deref;
use std::str::FromStr;

use glob::Pattern;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Unexpected, Visitor};

#[derive(Clone)]
pub struct Globber(pub Pattern);

impl Serialize for Globber {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where S: Serializer
  {
    serializer.serialize_str(self.as_str())
  }
}

impl Deserialize for Globber {
  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where D: Deserializer
  {
    struct VariantVisitor<__D> {
      _marker: PhantomData<__D>,
    }

    impl<__D> Visitor for VariantVisitor<__D>
      where __D: Deserializer
    {
      type Value = Globber;

      fn visit_str<E>(self, value: &str) -> Result<Globber, E>
        where E: ::serde::de::Error
      {
        Globber::from_str(value).map_err(|_| E::invalid_value(Unexpected::Str(value), &self))
      }

      fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        formatter.write_str("a valid file path glob expression")
      }
    }

    deserializer.deserialize_str(VariantVisitor::<D> { _marker: PhantomData, })
  }
}

impl FromStr for Globber {
  type Err = <Pattern as FromStr>::Err;

  fn from_str(s: &str) -> Result<Self, Self::Err> {
    Pattern::from_str(s).map(|p| Globber(p))
  }
}

impl Deref for Globber {
  type Target = Pattern;
  fn deref(&self) -> &Self::Target {
    &self.0
  }
}
{'fraction_non_alphanumeric': 0.15467625899280577, 'fraction_numerical': 0.0006540222367560497, 'mean_word_length': 3.663109756097561, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1027836', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1094, 'n_words': 237}