rskafka/protocol/
api_version.rs1use super::primitives::Int16;
2
3#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
4#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
5pub struct ApiVersion(pub Int16);
6
7#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8pub struct ApiVersionRange {
9 min: ApiVersion,
10 max: ApiVersion,
11}
12
13impl std::fmt::Display for ApiVersion {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 write!(f, "{}", self.0 .0)
16 }
17}
18
19impl ApiVersionRange {
20 pub const fn new(min: ApiVersion, max: ApiVersion) -> Self {
21 assert!(min.0 .0 <= max.0 .0);
22
23 Self { min, max }
24 }
25
26 pub fn min(&self) -> ApiVersion {
27 self.min
28 }
29
30 pub fn max(&self) -> ApiVersion {
31 self.max
32 }
33}
34
35impl std::fmt::Display for ApiVersionRange {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "{}:{}", self.min, self.max)
38 }
39}