writeable/
either.rs

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
5use crate::*;
6use ::either::Either;
7
8/// A [`Writeable`] impl that delegates to one type or another type.
9impl<W0, W1> Writeable for Either<W0, W1>
10where
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 write_to_string(&self) -> Cow<str> {
36        match self {
37            Either::Left(w) => w.write_to_string(),
38            Either::Right(w) => w.write_to_string(),
39        }
40    }
41}