legit-hashes 0.2.0

Versioned similarity hashes of images and text, and MinHash set signatures, with index keys for finding near matches
Documentation
//! Reading the string forms with `serde`, with the `serde` feature.

use std::fmt;
use std::marker::PhantomData;
use std::str::FromStr;

/// A visitor that parses a string with `T`'s [`FromStr`].
pub(crate) struct FromStrVisitor<T> {
    expecting: &'static str,
    target: PhantomData<T>,
}

impl<T> FromStrVisitor<T> {
    pub(crate) const fn new(expecting: &'static str) -> Self {
        Self {
            expecting,
            target: PhantomData,
        }
    }
}

impl<T> serde::de::Visitor<'_> for FromStrVisitor<T>
where
    T: FromStr,
    T::Err: fmt::Display,
{
    type Value = T;

    fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.expecting)
    }

    fn visit_str<E: serde::de::Error>(self, text: &str) -> Result<T, E> {
        text.parse().map_err(E::custom)
    }
}