From 51622451bd3d81918f14ae0c8b05de7637ac0649 Mon Sep 17 00:00:00 2001 From: timofey Date: Tue, 1 Aug 2023 11:32:23 +0000 Subject: [PATCH] shorten lines in `mode.md` code --- src/exercises/mode.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/exercises/mode.md b/src/exercises/mode.md index bb74e5f..e105522 100644 --- a/src/exercises/mode.md +++ b/src/exercises/mode.md @@ -22,7 +22,7 @@ trait FromStream: Sized { type Error; } -/// Can be formed from any length of data. Always consumes the stream. +/// Can be constructed from data of any length. Always consumes the stream. trait ConsumesStream: FromStream { /// Try to read the value. Can handle EOF, can ask for all data the stream has. fn read_from(stream: impl Stream) -> Result; @@ -51,19 +51,26 @@ impl FromStream for (A, B) { impl ConsumesStream for (A, B) { fn read_from(stream: impl Stream) -> Result { - let (a, stream) = A::read_from(stream).map_err(Either::Left)?; - B::read_from(stream).map_err(Either::Right).map(|b| (a, b)) + let (a, stream) = A::read_from(stream) + .map_err(Either::Left)?; + B::read_from(stream) + .map_err(Either::Right) + .map(|b| (a, b)) } fn extend(self, data: &[u8]) -> Result { - self.1.extend(data).map_err(Either::Right).map(|b| (self.0, b)) + self.1.extend(data) + .map_err(Either::Right).map(|b| (self.0, b)) } } impl Deterministic for (A, B) { fn read_from(stream: S) -> Result<(Self, S), Self::Error> { - let (a, stream) = A::read_from(stream).map_err(Either::Left)?; - B::read_from(stream).map_err(Either::Right).map(|(b, stream)| ((a, b), stream)) + let (a, stream) = A::read_from(stream) + .map_err(Either::Left)?; + B::read_from(stream) + .map_err(Either::Right) + .map(|(b, stream)| ((a, b), stream)) } fn fail(data: &[u8]) -> Self::Error {