Debian Codegraph @

debian/missing-sources/writeable/src/either.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 crate::*;
6 use ::either::Either;
7
8 /// A [`Writeable`] impl that delegates to one type or another type.
9 impl<W0, W1> Writeable for Either<W0, W1>
10 where
11 W0: Writeable,
12 W1: Writeable,
13 {
14 fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
15 match self {
16 Either::Left(w) => w.write_to(sink),
17 Either::Right(w) => w.write_to(sink),
18 }
19 }
20
21 fn write_to_parts<S: PartsWrite + ?Sized>(&self, sink: &mut S) -> fmt::Result {
22 match self {
23 Either::Left(w) => w.write_to_parts(sink),
24 Either::Right(w) => w.write_to_parts(sink),
25 }
26 }
27
28 fn writeable_length_hint(&self) -> LengthHint {
29 match self {
30 Either::Left(w) => w.writeable_length_hint(),
31 Either::Right(w) => w.writeable_length_hint(),
32 }
33 }
34
35 fn writeable_borrow(&self) -> Option<&str> {
36 match self {
37 Either::Left(w) => w.writeable_borrow(),
38 Either::Right(w) => w.writeable_borrow(),
39 }
40 }
41
42 #[cfg(feature = "alloc")]
43 fn write_to_string(&self) -> Cow<'_, str> {
44 match self {
45 Either::Left(w) => w.write_to_string(),
46 Either::Right(w) => w.write_to_string(),
47 }
48 }
49 }