Debian Codegraph @

debian/missing-sources/writeable/tests/writeable.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 use std::fmt;
6 use writeable::assert_writeable_eq;
7 use writeable::LengthHint;
8 use writeable::Writeable;
9
10 /// A sample type implementing Writeable
11 struct WriteableMessage<'s> {
12 message: &'s str,
13 }
14
15 impl Writeable for WriteableMessage<'_> {
16 fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
17 sink.write_str(self.message)
18 }
19
20 fn writeable_length_hint(&self) -> LengthHint {
21 LengthHint::exact(self.message.len())
22 }
23 }
24
25 writeable::impl_display_with_writeable!(WriteableMessage<'_>);
26
27 #[test]
28 fn test_basic() {
29 let input_string = "hello world";
30 let message = WriteableMessage {
31 message: input_string,
32 };
33 assert_writeable_eq!(&message, input_string);
34 }