From e8b1f87e9afd21af38df8ecb9864cf5c2702f3b5 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 21 Nov 2024 15:35:05 +1100 Subject: [PATCH] VersionRange additions --- src/protocol/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index ddf211b..5d70ee2 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -1,10 +1,10 @@ //! Most types are used internally in encoding/decoding, and are not required by typical use cases //! for interacting with the protocol. However, types can be used for decoding partial messages, //! or rewriting parts of an encoded message. -use std::borrow::Borrow; use std::cmp; use std::collections::BTreeMap; use std::ops::RangeBounds; +use std::{borrow::Borrow, fmt::Display}; use anyhow::{bail, Result}; use buf::{ByteBuf, ByteBufMut}; @@ -128,7 +128,7 @@ pub(crate) trait Decoder { } /// The range of versions (min, max) allowed for agiven message. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct VersionRange { /// The minimum version in the range. pub min: i16, @@ -151,6 +151,12 @@ impl VersionRange { } } +impl Display for VersionRange { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}..{}", self.min, self.max) + } +} + /// An API request or response. /// /// All API messages must provide a set of valid versions.