musli_core/de/decode_unsized_bytes.rs
1use super::Decoder;
2
3/// A trait implemented for types which can be visited by reference.
4///
5/// This behaves the same as [`DecodeUnsized`], but implicitly hints that the
6/// caller is after bytes.
7///
8/// This is used for types like `[u8]` which are unsized, and might require
9/// internal allocating to properly decode. Simply using the `Decode`
10/// implementation would restrict it to only be used through `&'de [u8]` which
11/// would demand an exact reference to data from the decoded source.
12///
13/// [`DecodeUnsized`]: super::DecodeUnsized
14pub trait DecodeUnsizedBytes<'de, M> {
15 /// Decode the given input using a closure as visitor.
16 fn decode_unsized_bytes<D, F, O>(cx: &D::Cx, decoder: D, f: F) -> Result<O, D::Error>
17 where
18 D: Decoder<'de, Mode = M>,
19 F: FnOnce(&Self) -> Result<O, D::Error>;
20}