Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Extract `SemanticVersion` into its own crate (#9956)
Marshall Bowers16e6f5643cec
diff --git a/Cargo.lock b/Cargo.lockindex bdc1909ca94..bdade5e85c0 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2265,6 +2265,7 @@ dependencies = ["rustc-demangle","scrypt","sea-orm",+ "semantic_version","semver","serde","serde_derive",@@ -3558,6 +3559,7 @@ dependencies = ["parking_lot","project","schemars",+ "semantic_version","serde","serde_json","serde_json_lenient",@@ -3610,6 +3612,7 @@ dependencies = ["language","picker","project",+ "semantic_version","serde","settings","smallvec",@@ -4446,6 +4449,7 @@ dependencies = ["resvg","schemars","seahash",+ "semantic_version","serde","serde_derive","serde_json",@@ -8496,6 +8500,14 @@ version = "1.0.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba"+[[package]]+name = "semantic_version"+version = "0.1.0"+dependencies = [+ "anyhow",+ "serde",+]+[[package]]name = "semver"version = "1.0.18"@@ -9659,8 +9671,8 @@ dependencies = [name = "telemetry_events"version = "0.1.0"dependencies = [+ "semantic_version","serde",- "util",][[package]]diff --git a/Cargo.toml b/Cargo.tomlindex 54a1ef9cac9..b3c4d205148 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -70,6 +70,7 @@ members = ["crates/task","crates/tasks_ui","crates/search",+ "crates/semantic_version","crates/settings","crates/snippet","crates/sqlez",@@ -184,6 +185,7 @@ rpc = { path = "crates/rpc" }task = { path = "crates/task" }tasks_ui = { path = "crates/tasks_ui" }search = { path = "crates/search" }+semantic_version = { path = "crates/semantic_version" }settings = { path = "crates/settings" }snippet = { path = "crates/snippet" }sqlez = { path = "crates/sqlez" }diff --git a/crates/collab/Cargo.toml b/crates/collab/Cargo.tomlindex ad61aa83794..cb0f1b1f8a9 100644--- a/crates/collab/Cargo.toml+++ b/crates/collab/Cargo.toml@@ -46,6 +46,7 @@ reqwest = { version = "0.11", features = ["json"] }rpc.workspace = truescrypt = "0.7"sea-orm = { version = "0.12.x", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls", "with-uuid"] }+semantic_version.workspace = truesemver.workspace = trueserde.workspace = trueserde_derive.workspace = truediff --git a/crates/collab/src/api/events.rs b/crates/collab/src/api/events.rsindex 18825943344..95abad18202 100644--- a/crates/collab/src/api/events.rs+++ b/crates/collab/src/api/events.rs@@ -10,6 +10,7 @@ use axum::{Extension, Router, TypedHeader,};use rpc::ExtensionMetadata;+use semantic_version::SemanticVersion;use serde::{Serialize, Serializer};use sha2::{Digest, Sha256};use std::sync::{Arc, OnceLock};@@ -17,7 +18,6 @@ use telemetry_events::{ActionEvent, AppEvent, AssistantEvent, CallEvent, CopilotEvent, CpuEvent, EditEvent,EditorEvent, Event, EventRequestBody, EventWrapper, ExtensionEvent, MemoryEvent, SettingEvent,};-use util::SemanticVersion;pub fn router() -> Router {Router::new()@@ -528,9 +528,9 @@ impl EditorEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),os_name: body.os_name.clone(),os_version: body.os_version.clone().unwrap_or_default(),@@ -590,9 +590,9 @@ impl CopilotEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),os_name: body.os_name.clone(),os_version: body.os_version.clone().unwrap_or_default(),@@ -645,9 +645,9 @@ impl CallEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone().unwrap_or_default(),session_id: body.session_id.clone(),@@ -694,9 +694,9 @@ impl AssistantEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -738,9 +738,9 @@ impl CpuEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -785,9 +785,9 @@ impl MemoryEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -831,9 +831,9 @@ impl AppEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -876,9 +876,9 @@ impl SettingEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -927,9 +927,9 @@ impl ExtensionEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -991,9 +991,9 @@ impl EditEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),@@ -1040,9 +1040,9 @@ impl ActionEventRow {Self {app_version: body.app_version.clone(),- major: semver.map(|s| s.major as i32),- minor: semver.map(|s| s.minor as i32),- patch: semver.map(|s| s.patch as i32),+ major: semver.map(|v| v.major() as i32),+ minor: semver.map(|v| v.minor() as i32),+ patch: semver.map(|v| v.patch() as i32),release_channel: body.release_channel.clone().unwrap_or_default(),installation_id: body.installation_id.clone(),session_id: body.session_id.clone(),diff --git a/crates/collab/src/api/ips_file.rs b/crates/collab/src/api/ips_file.rsindex cbbf042abf9..0f5fbcc2520 100644--- a/crates/collab/src/api/ips_file.rs+++ b/crates/collab/src/api/ips_file.rs@@ -1,9 +1,8 @@use collections::HashMap;-use serde_derive::Deserialize;-use serde_derive::Serialize;+use semantic_version::SemanticVersion;+use serde::{Deserialize, Serialize};use serde_json::Value;-use util::SemanticVersion;#[derive(Debug)]pub struct IpsFile {diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rsindex 84c8ba465c9..af2cdb75acd 100644--- a/crates/collab/src/rpc.rs+++ b/crates/collab/src/rpc.rs@@ -46,6 +46,7 @@ use rpc::{},Connection, ConnectionId, ErrorCode, ErrorCodeExt, ErrorExt, Peer, Receipt, TypedEnvelope,};+use semantic_version::SemanticVersion;use serde::{Serialize, Serializer};use std::{any::TypeId,@@ -68,7 +69,7 @@ use tracing::{field::{self},info_span, instrument, Instrument,};-use util::{http::IsahcHttpClient, SemanticVersion};+use util::http::IsahcHttpClient;pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);diff --git a/crates/collab/src/rpc/connection_pool.rs b/crates/collab/src/rpc/connection_pool.rsindex 9d83b394e6b..33def0b9bb5 100644--- a/crates/collab/src/rpc/connection_pool.rs+++ b/crates/collab/src/rpc/connection_pool.rs@@ -2,9 +2,10 @@ use crate::db::{ChannelId, ChannelRole, UserId};use anyhow::{anyhow, Result};use collections::{BTreeMap, HashMap, HashSet};use rpc::ConnectionId;+use semantic_version::SemanticVersion;use serde::Serialize;+use std::fmt;use tracing::instrument;-use util::{semver, SemanticVersion};#[derive(Default, Serialize)]pub struct ConnectionPool {@@ -20,7 +21,6 @@ struct ConnectedUser {#[derive(Debug, Serialize)]pub struct ZedVersion(pub SemanticVersion);-use std::fmt;impl fmt::Display for ZedVersion {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {@@ -30,7 +30,7 @@ impl fmt::Display for ZedVersion {impl ZedVersion {pub fn can_collaborate(&self) -> bool {- self.0 >= semver(0, 127, 3)+ self.0 >= SemanticVersion::new(0, 127, 3)}}diff --git a/crates/collab/src/tests/test_server.rs b/crates/collab/src/tests/test_server.rsindex 3027848b2be..64be8cb09b1 100644--- a/crates/collab/src/tests/test_server.rs+++ b/crates/collab/src/tests/test_server.rs@@ -19,7 +19,6 @@ use futures::{channel::oneshot, StreamExt as _};use gpui::{BackgroundExecutor, Context, Model, Task, TestAppContext, View, VisualTestContext};use language::LanguageRegistry;use node_runtime::FakeNodeRuntime;-use notifications::NotificationStore;use parking_lot::Mutex;use project::{Project, WorktreeId};@@ -27,6 +26,7 @@ use rpc::{proto::{self, ChannelRole},RECEIVE_TIMEOUT,};+use semantic_version::SemanticVersion;use serde_json::json;use settings::SettingsStore;use std::{@@ -39,7 +39,7 @@ use std::{Arc,},};-use util::{http::FakeHttpClient, SemanticVersion};+use util::http::FakeHttpClient;use workspace::{Workspace, WorkspaceId, WorkspaceStore};pub struct TestServer {diff --git a/crates/extension/Cargo.toml b/crates/extension/Cargo.tomlindex fdd7bfb6ce1..e9b02c72dd2 100644--- a/crates/extension/Cargo.toml+++ b/crates/extension/Cargo.toml@@ -33,6 +33,7 @@ lsp.workspace = truenode_runtime.workspace = trueproject.workspace = trueschemars.workspace = true+semantic_version.workspace = trueserde.workspace = trueserde_json.workspace = truesettings.workspace = truediff --git a/crates/extension/src/extension_manifest.rs b/crates/extension/src/extension_manifest.rsindex 63d3da51c18..5e390637c05 100644--- a/crates/extension/src/extension_manifest.rs+++ b/crates/extension/src/extension_manifest.rs@@ -2,6 +2,7 @@ use anyhow::{anyhow, Context, Result};use collections::BTreeMap;use fs::Fs;use language::LanguageServerName;+use semantic_version::SemanticVersion;use serde::{Deserialize, Serialize};use std::{ffi::OsStr,@@ -9,7 +10,6 @@ use std::{path::{Path, PathBuf},sync::Arc,};-use util::SemanticVersion;/// This is the old version of the extension manifest, from when it was `extension.json`.#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]diff --git a/crates/extension/src/extension_store.rs b/crates/extension/src/extension_store.rsindex 2658f7f03b0..22a4923f685 100644--- a/crates/extension/src/extension_store.rs+++ b/crates/extension/src/extension_store.rs@@ -33,6 +33,7 @@ use language::{QUERY_FILENAME_PREFIXES,};use node_runtime::NodeRuntime;+use semantic_version::SemanticVersion;use serde::{Deserialize, Serialize};use settings::Settings;use std::str::FromStr;@@ -44,7 +45,6 @@ use std::{};use theme::{ThemeRegistry, ThemeSettings};use url::Url;-use util::SemanticVersion;use util::{http::{AsyncBody, HttpClient, HttpClientWithUrl},maybe,diff --git a/crates/extension/src/wasm_host.rs b/crates/extension/src/wasm_host.rsindex b610db205e0..6bfe6537f12 100644--- a/crates/extension/src/wasm_host.rs+++ b/crates/extension/src/wasm_host.rs@@ -14,11 +14,12 @@ use futures::{use gpui::BackgroundExecutor;use language::LanguageRegistry;use node_runtime::NodeRuntime;+use semantic_version::SemanticVersion;use std::{path::{Path, PathBuf},sync::{Arc, OnceLock},};-use util::{http::HttpClient, SemanticVersion};+use util::http::HttpClient;use wasmtime::{component::{Component, ResourceTable},Engine, Store,@@ -203,11 +204,11 @@ pub fn parse_wasm_extension_version(fn parse_wasm_extension_version_custom_section(data: &[u8]) -> Option<SemanticVersion> {if data.len() == 6 {- Some(SemanticVersion {- major: u16::from_be_bytes([data[0], data[1]]) as _,- minor: u16::from_be_bytes([data[2], data[3]]) as _,- patch: u16::from_be_bytes([data[4], data[5]]) as _,- })+ Some(SemanticVersion::new(+ u16::from_be_bytes([data[0], data[1]]) as _,+ u16::from_be_bytes([data[2], data[3]]) as _,+ u16::from_be_bytes([data[4], data[5]]) as _,+ ))} else {None}diff --git a/crates/extension/src/wasm_host/wit.rs b/crates/extension/src/wasm_host/wit.rsindex 321aa40ad07..00d69acd1e2 100644--- a/crates/extension/src/wasm_host/wit.rs+++ b/crates/extension/src/wasm_host/wit.rs@@ -4,8 +4,8 @@ mod v0_0_4;use super::{wasm_engine, WasmState};use anyhow::{Context, Result};use language::LspAdapterDelegate;+use semantic_version::SemanticVersion;use std::sync::Arc;-use util::SemanticVersion;use wasmtime::{component::{Component, Instance, Linker, Resource},Store,diff --git a/crates/extension/src/wasm_host/wit/v0_0_1.rs b/crates/extension/src/wasm_host/wit/v0_0_1.rsindex 212231a1d9c..29d9d2ee059 100644--- a/crates/extension/src/wasm_host/wit/v0_0_1.rs+++ b/crates/extension/src/wasm_host/wit/v0_0_1.rs@@ -3,15 +3,11 @@ use crate::wasm_host::WasmState;use anyhow::Result;use async_trait::async_trait;use language::{LanguageServerBinaryStatus, LspAdapterDelegate};+use semantic_version::SemanticVersion;use std::sync::{Arc, OnceLock};-use util::SemanticVersion;use wasmtime::component::{Linker, Resource};-pub const VERSION: SemanticVersion = SemanticVersion {- major: 0,- minor: 0,- patch: 1,-};+pub const VERSION: SemanticVersion = SemanticVersion::new(0, 0, 1);wasmtime::component::bindgen!({async: true,diff --git a/crates/extension/src/wasm_host/wit/v0_0_4.rs b/crates/extension/src/wasm_host/wit/v0_0_4.rsindex 68bc66b9d35..24acb3c7c21 100644--- a/crates/extension/src/wasm_host/wit/v0_0_4.rs+++ b/crates/extension/src/wasm_host/wit/v0_0_4.rs@@ -5,19 +5,16 @@ use async_tar::Archive;use async_trait::async_trait;use futures::io::BufReader;use language::{LanguageServerBinaryStatus, LspAdapterDelegate};+use semantic_version::SemanticVersion;use std::{env,path::PathBuf,sync::{Arc, OnceLock},};-use util::{maybe, SemanticVersion};+use util::maybe;use wasmtime::component::{Linker, Resource};-pub const VERSION: SemanticVersion = SemanticVersion {- major: 0,- minor: 0,- patch: 4,-};+pub const VERSION: SemanticVersion = SemanticVersion::new(0, 0, 4);wasmtime::component::bindgen!({async: true,diff --git a/crates/extensions_ui/Cargo.toml b/crates/extensions_ui/Cargo.tomlindex b9f13c75df9..586739f46ca 100644--- a/crates/extensions_ui/Cargo.toml+++ b/crates/extensions_ui/Cargo.toml@@ -26,6 +26,7 @@ gpui.workspace = truelanguage.workspace = truepicker.workspace = trueproject.workspace = true+semantic_version.workspace = trueserde.workspace = truesettings.workspace = truesmallvec.workspace = truediff --git a/crates/extensions_ui/src/extension_version_selector.rs b/crates/extensions_ui/src/extension_version_selector.rsindex a893b7bbb9c..986a71a371a 100644--- a/crates/extensions_ui/src/extension_version_selector.rs+++ b/crates/extensions_ui/src/extension_version_selector.rs@@ -9,9 +9,10 @@ use gpui::{prelude::*, AppContext, DismissEvent, EventEmitter, FocusableView, Task, View, WeakView,};use picker::{Picker, PickerDelegate};+use semantic_version::SemanticVersion;use settings::update_settings_file;use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing};-use util::{ResultExt, SemanticVersion};+use util::ResultExt;use workspace::ModalView;pub struct ExtensionVersionSelector {diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex 210ba4129af..d27f9a353d3 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -57,6 +57,7 @@ refineable.workspace = trueresvg = "0.40"schemars.workspace = trueseahash = "4.1"+semantic_version.workspace = trueserde.workspace = trueserde_derive.workspace = trueserde_json.workspace = truediff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex 24c6a62e848..958fe78f0de 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -53,10 +53,10 @@ pub use keystroke::*;pub(crate) use linux::*;#[cfg(target_os = "macos")]pub(crate) use mac::*;+pub use semantic_version::SemanticVersion;#[cfg(any(test, feature = "test-support"))]pub(crate) use test::*;use time::UtcOffset;-pub use util::SemanticVersion;#[cfg(target_os = "windows")]pub(crate) use windows::*;diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rsindex c19e2f47af9..c059183d875 100644--- a/crates/gpui/src/platform/linux/platform.rs+++ b/crates/gpui/src/platform/linux/platform.rs@@ -353,19 +353,11 @@ impl Platform for LinuxPlatform {}fn os_version(&self) -> Result<SemanticVersion> {- Ok(SemanticVersion {- major: 1,- minor: 0,- patch: 0,- })+ Ok(SemanticVersion::new(1, 0, 0))}fn app_version(&self) -> Result<SemanticVersion> {- Ok(SemanticVersion {- major: 1,- minor: 0,- patch: 0,- })+ Ok(SemanticVersion::new(1, 0, 0))}fn app_path(&self) -> Result<PathBuf> {diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rsindex 0227a1061ac..0ba22e96469 100644--- a/crates/gpui/src/platform/mac/platform.rs+++ b/crates/gpui/src/platform/mac/platform.rs@@ -718,11 +718,11 @@ impl Platform for MacPlatform {unsafe {let process_info = NSProcessInfo::processInfo(nil);let version = process_info.operatingSystemVersion();- Ok(SemanticVersion {- major: version.majorVersion as usize,- minor: version.minorVersion as usize,- patch: version.patchVersion as usize,- })+ Ok(SemanticVersion::new(+ version.majorVersion as usize,+ version.minorVersion as usize,+ version.patchVersion as usize,+ ))}}diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rsindex 609749b98d0..743b184f720 100644--- a/crates/gpui/src/platform/windows/platform.rs+++ b/crates/gpui/src/platform/windows/platform.rs@@ -12,13 +12,14 @@ use std::{sync::{Arc, OnceLock},};-use ::util::{ResultExt, SemanticVersion};+use ::util::ResultExt;use anyhow::{anyhow, Context, Result};use async_task::Runnable;use copypasta::{ClipboardContext, ClipboardProvider};use futures::channel::oneshot::{self, Receiver};use itertools::Itertools;use parking_lot::{Mutex, RwLock};+use semantic_version::SemanticVersion;use smallvec::SmallVec;use time::UtcOffset;use windows::{@@ -513,11 +514,11 @@ impl Platform for WindowsPlatform {let mut info = unsafe { std::mem::zeroed() };let status = unsafe { RtlGetVersion(&mut info) };if status.is_ok() {- Ok(SemanticVersion {- major: info.dwMajorVersion as _,- minor: info.dwMinorVersion as _,- patch: info.dwBuildNumber as _,- })+ Ok(SemanticVersion::new(+ info.dwMajorVersion as _,+ info.dwMinorVersion as _,+ info.dwBuildNumber as _,+ ))} else {Err(anyhow::anyhow!("unable to get Windows version: {}",@@ -606,11 +607,11 @@ impl Platform for WindowsPlatform {let version_info = unsafe { &*(version_info_raw as *mut VS_FIXEDFILEINFO) };// https://learn.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfoif version_info.dwSignature == 0xFEEF04BD {- return Ok(SemanticVersion {- major: ((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,- minor: (version_info.dwProductVersionMS & 0xFFFF) as usize,- patch: ((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,- });+ return Ok(SemanticVersion::new(+ ((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,+ (version_info.dwProductVersionMS & 0xFFFF) as usize,+ ((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,+ ));} else {log::error!("no version info present: {}",diff --git a/crates/semantic_version/Cargo.toml b/crates/semantic_version/Cargo.tomlnew file mode 100644index 00000000000..acf43cddfa0--- /dev/null+++ b/crates/semantic_version/Cargo.toml@@ -0,0 +1,16 @@+[package]+name = "semantic_version"+version = "0.1.0"+edition = "2021"+publish = false+license = "Apache-2.0"++[lints]+workspace = true++[lib]+path = "src/semantic_version.rs"++[dependencies]+anyhow.workspace = true+serde.workspace = truediff --git a/crates/semantic_version/LICENSE-APACHE b/crates/semantic_version/LICENSE-APACHEnew file mode 120000index 00000000000..1cd601d0a3a--- /dev/null+++ b/crates/semantic_version/LICENSE-APACHE@@ -0,0 +1 @@+../../LICENSE-APACHE\ No newline at end of filediff --git a/crates/util/src/semantic_version.rs b/crates/semantic_version/src/semantic_version.rssimilarity index 71%rename from crates/util/src/semantic_version.rsrename to crates/semantic_version/src/semantic_version.rsindex 77c1a88ed22..243ac91e13a 100644--- a/crates/util/src/semantic_version.rs+++ b/crates/semantic_version/src/semantic_version.rs@@ -1,3 +1,7 @@+//! Constructs for working with [semantic versions](https://semver.org/).++#![deny(missing_docs)]+use std::{fmt::{self, Display},str::FromStr,@@ -6,34 +10,46 @@ use std::{use anyhow::{anyhow, Result};use serde::{de::Error, Deserialize, Serialize};-/// A datastructure representing a semantic version number+/// A [semantic version](https://semver.org/) number.#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]pub struct SemanticVersion {- pub major: usize,- pub minor: usize,- pub patch: usize,-}--pub fn semver(major: usize, minor: usize, patch: usize) -> SemanticVersion {- SemanticVersion {- major,- minor,- patch,- }+ major: usize,+ minor: usize,+ patch: usize,}impl SemanticVersion {- pub fn new(major: usize, minor: usize, patch: usize) -> Self {+ /// Returns a new [`SemanticVersion`] from the given components.+ pub const fn new(major: usize, minor: usize, patch: usize) -> Self {Self {major,minor,patch,}}++ /// Returns the major version number.+ #[inline(always)]+ pub fn major(&self) -> usize {+ self.major+ }++ /// Returns the minor version number.+ #[inline(always)]+ pub fn minor(&self) -> usize {+ self.minor+ }++ /// Returns the patch version number.+ #[inline(always)]+ pub fn patch(&self) -> usize {+ self.patch+ }}impl FromStr for SemanticVersion {type Err = anyhow::Error;+fn from_str(s: &str) -> Result<Self> {let mut components = s.trim().split('.');let major = componentsdiff --git a/crates/telemetry_events/Cargo.toml b/crates/telemetry_events/Cargo.tomlindex b202a60b251..01145549b15 100644--- a/crates/telemetry_events/Cargo.toml+++ b/crates/telemetry_events/Cargo.toml@@ -12,5 +12,5 @@ workspace = truepath = "src/telemetry_events.rs"[dependencies]+semantic_version.workspace = trueserde.workspace = true-util.workspace = truediff --git a/crates/telemetry_events/src/telemetry_events.rs b/crates/telemetry_events/src/telemetry_events.rsindex f27e9a49e06..3eb86ab4dd5 100644--- a/crates/telemetry_events/src/telemetry_events.rs+++ b/crates/telemetry_events/src/telemetry_events.rs@@ -1,6 +1,6 @@+use semantic_version::SemanticVersion;use serde::{Deserialize, Serialize};use std::{fmt::Display, sync::Arc};-use util::SemanticVersion;#[derive(Serialize, Deserialize, Debug)]pub struct EventRequestBody {diff --git a/crates/util/src/util.rs b/crates/util/src/util.rsindex 30ca1b9b71e..5754c17b645 100644--- a/crates/util/src/util.rs+++ b/crates/util/src/util.rs@@ -3,14 +3,12 @@ pub mod fs;pub mod github;pub mod http;pub mod paths;-mod semantic_version;#[cfg(any(test, feature = "test-support"))]pub mod test;use futures::Future;use lazy_static::lazy_static;use rand::{seq::SliceRandom, Rng};-pub use semantic_version::*;use std::{borrow::Cow,cmp::{self, Ordering},