vergen_pretty/pretty/feature/
bincode.rs

1// Copyright (c) 2022 vergen developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9use bincode::{
10    BorrowDecode, Decode, Encode,
11    de::{BorrowDecoder, Decoder},
12    enc::Encoder,
13    error::{DecodeError, EncodeError},
14};
15
16use crate::{Prefix, Suffix};
17
18impl Encode for Prefix {
19    fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
20        self.lines.encode(encoder)?;
21        Ok(())
22    }
23}
24
25impl<Context> Decode<Context> for Prefix {
26    fn decode<D: Decoder<Context = Context>>(decoder: &mut D) -> Result<Self, DecodeError> {
27        Ok(Prefix::builder()
28            .lines(Vec::<String>::decode(decoder)?)
29            .build())
30    }
31}
32
33impl<'de, Context> BorrowDecode<'de, Context> for Prefix {
34    fn borrow_decode<D: BorrowDecoder<'de, Context = Context>>(
35        decoder: &mut D,
36    ) -> Result<Self, DecodeError> {
37        Ok(Prefix::builder()
38            .lines(Vec::<String>::borrow_decode(decoder)?)
39            .build())
40    }
41}
42
43impl Encode for Suffix {
44    fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
45        self.lines.encode(encoder)?;
46        Ok(())
47    }
48}
49
50impl<Context> Decode<Context> for Suffix {
51    fn decode<D: Decoder<Context = Context>>(decoder: &mut D) -> Result<Self, DecodeError> {
52        Ok(Suffix::builder()
53            .lines(Vec::<String>::decode(decoder)?)
54            .build())
55    }
56}
57
58impl<'de, Context> BorrowDecode<'de, Context> for Suffix {
59    fn borrow_decode<D: BorrowDecoder<'de, Context = Context>>(
60        decoder: &mut D,
61    ) -> Result<Self, DecodeError> {
62        Ok(Suffix::builder()
63            .lines(Vec::<String>::borrow_decode(decoder)?)
64            .build())
65    }
66}