1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use core::fmt;
use core::marker;

use musli::de::ValueVisitor;
use musli::Context;

use crate::parser::integer::Unsigned;
use crate::parser::SliceParser;

use super::parse_unsigned;

pub(crate) struct KeyUnsignedVisitor<T> {
    _marker: marker::PhantomData<T>,
}

impl<T> KeyUnsignedVisitor<T> {
    pub(super) const fn new() -> Self {
        Self {
            _marker: marker::PhantomData,
        }
    }
}

impl<'de, C, T> ValueVisitor<'de, C, [u8]> for KeyUnsignedVisitor<T>
where
    C: ?Sized + Context,
    T: Unsigned,
{
    type Ok = T;

    #[inline]
    fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "bytes")
    }

    #[inline]
    fn visit_ref(self, cx: &C, bytes: &[u8]) -> Result<Self::Ok, C::Error> {
        parse_unsigned(cx, &mut SliceParser::new(bytes))
    }
}