use std::fmt;
pub const MEMORY_PLACEMENT: ServerVersion = ServerVersion::new(1, 19, 0);
pub const TURBO4_DATATYPE: ServerVersion = ServerVersion::new(1, 18, 2);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ServerVersion {
pub major: u32,
pub minor: u32,
pub patch: u32,
}
impl ServerVersion {
pub const fn new(major: u32, minor: u32, patch: u32) -> Self {
ServerVersion {
major,
minor,
patch,
}
}
pub fn parse(s: &str) -> Option<Self> {
let core = s
.trim()
.trim_start_matches('v')
.split(['-', '+'])
.next()?
.trim();
let mut parts = core.split('.');
let major = parts.next()?.parse().ok()?;
let minor = parts.next()?.parse().ok()?;
let patch = match parts.next() {
Some(p) => p.parse().ok()?,
None => 0,
};
Some(ServerVersion::new(major, minor, patch))
}
}
impl fmt::Display for ServerVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VersionRequirement {
pub version: ServerVersion,
pub feature: String,
}
impl VersionRequirement {
pub fn new(version: ServerVersion, feature: impl Into<String>) -> Self {
VersionRequirement {
version,
feature: feature.into(),
}
}
}
pub(crate) fn require(
out: &mut Vec<VersionRequirement>,
version: ServerVersion,
feature: impl Into<String>,
) {
out.push(VersionRequirement::new(version, feature));
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_the_shapes_qdrant_reports() {
assert_eq!(
ServerVersion::parse("1.19.0"),
Some(ServerVersion::new(1, 19, 0))
);
assert_eq!(
ServerVersion::parse("v1.18.2"),
Some(ServerVersion::new(1, 18, 2))
);
assert_eq!(
ServerVersion::parse("1.19"),
Some(ServerVersion::new(1, 19, 0))
);
assert_eq!(
ServerVersion::parse("1.19.0-rc.1"),
Some(ServerVersion::new(1, 19, 0))
);
assert_eq!(ServerVersion::parse("nightly"), None);
assert_eq!(ServerVersion::parse("1.19.x"), None);
}
#[test]
fn orders_by_component() {
assert!(ServerVersion::new(1, 18, 2) < ServerVersion::new(1, 19, 0));
assert!(ServerVersion::new(1, 18, 10) > ServerVersion::new(1, 18, 2));
assert!(ServerVersion::new(2, 0, 0) > ServerVersion::new(1, 99, 99));
}
}