pub struct ProtocolVersion(/* private fields */);Expand description
An S2 JSON version string as it appears on the wire.
S2 negotiates versions by exact string match: S2C §Versioning of JSON Schema files says “the exact version string must be used (e.g. v1.0.0)”. No semver
range is involved, and none should be inferred — s2energy parses the peer’s string
as a VersionReq, which accepts strings the peer never offered.
The complication is that the deployed ecosystem negotiates "0.0.2-beta" — the tag
that predates S2 JSON v1.0.0 — while the schemas are tagged v1.0.0. Both are
supported; WireProfile is what a version string means for the wire.
Every version this crate speaks is an associated constant of this type, in both spellings, so naming one costs nothing and mentions it once:
use s2_kit::{ProtocolVersion, WireProfile};
// What an S2 JSON handshake writes, and what S2 Connect writes (erratum E25).
assert_eq!(ProtocolVersion::V1_0_0.as_str(), "1.0.0");
assert_eq!(ProtocolVersion::V1_0_0_CONNECT.as_str(), "v1.0.0");
// Same version either way.
assert!(ProtocolVersion::V1_0_0.matches(&ProtocolVersion::V1_0_0_CONNECT));
// And a profile hands out both without allocating.
assert_eq!(WireProfile::V0_0_2Beta.version(), ProtocolVersion::V0_0_2_BETA);Implementations§
Source§impl ProtocolVersion
impl ProtocolVersion
Sourcepub const V0_0_2_BETA: Self
pub const V0_0_2_BETA: Self
S2 JSON v0.0.2-beta, what every deployed implementation still negotiates.
Sourcepub const V1_0_0_CONNECT: Self
pub const V1_0_0_CONNECT: Self
S2 JSON v1.0.0 as S2 Connect spells it, with the v (erratum E25).
Sourcepub const V0_0_2_BETA_CONNECT: Self
pub const V0_0_2_BETA_CONNECT: Self
S2 JSON v0.0.2-beta as S2 Connect spells it, with the v (erratum E25).
Sourcepub fn new(s: impl Into<String>) -> Self
pub fn new(s: impl Into<String>) -> Self
Wrap a version string exactly as it will appear on the wire.
Sourcepub const fn from_static(s: &'static str) -> Self
pub const fn from_static(s: &'static str) -> Self
Wrap a 'static version string without allocating. const, and what the
associated constants above are built from.
Sourcepub fn canonical(&self) -> &str
pub fn canonical(&self) -> &str
The version without the optional v the two specifications disagree about.
S2C requires v1.0.0, every S2 JSON handshake writes 1.0.0, and
s2energy-connection’s examples write v1. This crate transmits one spelling and
understands both (erratum E25).
Sourcepub fn matches(&self, other: &Self) -> bool
pub fn matches(&self, other: &Self) -> bool
Whether two version strings name the same version.
Exact match on the canonical form — not a semver range, which is how
s2energy accepts versions the peer never offered (D5). The leading v is the
only latitude.
Sourcepub fn wire_profile(&self) -> Option<WireProfile>
pub fn wire_profile(&self) -> Option<WireProfile>
Which wire shape this version string selects, if this crate knows it.
Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
Whether this crate can speak this version.
Trait Implementations§
Source§impl Clone for ProtocolVersion
impl Clone for ProtocolVersion
Source§impl Debug for ProtocolVersion
impl Debug for ProtocolVersion
Source§impl<'de> Deserialize<'de> for ProtocolVersion
impl<'de> Deserialize<'de> for ProtocolVersion
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ProtocolVersion
impl Display for ProtocolVersion
impl Eq for ProtocolVersion
Source§impl From<&str> for ProtocolVersion
impl From<&str> for ProtocolVersion
Source§impl From<String> for ProtocolVersion
impl From<String> for ProtocolVersion
Source§impl Hash for ProtocolVersion
impl Hash for ProtocolVersion
Source§impl Ord for ProtocolVersion
impl Ord for ProtocolVersion
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ProtocolVersion
impl PartialEq for ProtocolVersion
Source§impl PartialOrd for ProtocolVersion
impl PartialOrd for ProtocolVersion
Source§impl Serialize for ProtocolVersion
impl Serialize for ProtocolVersion
impl StructuralPartialEq for ProtocolVersion
Auto Trait Implementations§
impl Forget for ProtocolVersion
impl Freeze for ProtocolVersion
impl Move for ProtocolVersion
impl RefUnwindSafe for ProtocolVersion
impl Send for ProtocolVersion
impl Sync for ProtocolVersion
impl Unpin for ProtocolVersion
impl UnsafeUnpin for ProtocolVersion
impl UnwindSafe for ProtocolVersion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.