Debian Codegraph @

tests/issues/issue_431.rs

raw
1 #![cfg(all(feature = "std", feature = "derive"))]
2
3 extern crate std;
4
5 use bincode::{Decode, Encode};
6 use std::borrow::Cow;
7 use std::string::String;
8
9 #[derive(Decode, Encode, PartialEq, Debug)]
10 #[bincode(
11 decode_context = "()",
12 borrow_decode_bounds = "&'__de U<'a, A>: ::bincode::de::BorrowDecode<'__de, ()> + '__de, '__de: 'a"
13 )]
14 struct T<'a, A: Clone + Encode + Decode<()>> {
15 t: Cow<'a, U<'a, A>>,
16 }
17
18 #[derive(Clone, Decode, Encode, PartialEq, Debug)]
19 #[bincode(
20 decode_context = "()",
21 borrow_decode_bounds = "&'__de A: ::bincode::de::BorrowDecode<'__de, ()> + '__de, '__de: 'a"
22 )]
23 struct U<'a, A: Clone + Encode + Decode<()>> {
24 u: Cow<'a, A>,
25 }
26
27 #[test]
28 fn test() {
29 let u = U {
30 u: Cow::Owned(String::from("Hello world")),
31 };
32 let t = T {
33 t: Cow::Borrowed(&u),
34 };
35 let vec = bincode::encode_to_vec(&t, bincode::config::standard()).unwrap();
36
37 let (decoded, len): (T<String>, usize) =
38 bincode::decode_from_slice(&vec, bincode::config::standard()).unwrap();
39
40 assert_eq!(t, decoded);
41 assert_eq!(len, 12);
42 }