From a4442a7b546730bc7be42fdd34dfc0319e4a430e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Legrand?= Date: Sat, 31 Oct 2026 15:04:01 +0100 Subject: [PATCH 1/2] refactor(core): satisfy Clippy pedantic lints --- crates/core/src/catalog.rs | 33 ++++++++++++++++++++------------- crates/core/src/details.rs | 7 ++++++- crates/core/src/distro.rs | 4 +++- crates/core/src/feed.rs | 14 +++++++------- crates/core/src/lib.rs | 2 +- crates/core/src/platform.rs | 15 +++++++++++---- crates/core/src/protocol.rs | 12 +++++++----- crates/core/src/release.rs | 25 +++++++++++++++++++++++++ crates/core/src/status.rs | 8 ++++++-- crates/core/src/time.rs | 36 +++++++++++++++++++++--------------- crates/core/src/version.rs | 8 +++++++- 11 files changed, 114 insertions(+), 50 deletions(-) diff --git a/crates/core/src/catalog.rs b/crates/core/src/catalog.rs index 3e04ff94..1f92204e 100644 --- a/crates/core/src/catalog.rs +++ b/crates/core/src/catalog.rs @@ -6,7 +6,7 @@ //! keyed by the app id (`tr_ctx(app.id, app.tagline)` in `ui-egui`). /// Who makes an app. Official apps live under [`GITHUB_OWNER`]; a community app is maintained -/// outside ArtCraft and is labelled as such wherever it is shown. +/// outside `ArtCraft` and is labelled as such wherever it is shown. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum AppKind { Official, @@ -30,18 +30,18 @@ pub struct CraftApp { pub ink_dark: [u8; 3], /// GitHub `owner/repo`. pub repo: &'static str, - /// Older names its release assets may carry (PdfCraft shipped as PrintCraft until 0.2.1). + /// Older names its release assets may carry (`PdfCraft` shipped as `PrintCraft` until 0.2.1). pub former_ids: &'static [&'static str], - /// Older display names its installers registered (PdfCraft's MSI said PrintCraft until 0.2.1). + /// Older display names its installers registered (`PdfCraft`'s MSI said `PrintCraft` until 0.2.1). pub former_names: &'static [&'static str], pub kind: AppKind, /// Who publishes it, as the card's byline shows it (`ArtCraft`, `Tangency Labs`). pub publisher: &'static str, - /// The publisher its Windows installer names, when it isn't ArtCraft's (`Learning Machines LLC`). + /// The publisher its Windows installer names, when it isn't `ArtCraft`'s (`Learning Machines LLC`). pub msi_publisher: Option<&'static str>, /// The bundle id when it isn't `ai.storyteller.` (a community app brings its own). pub bundle: Option<&'static str>, - /// Older bundle ids its Flatpak shipped under (SolidCraft was `ai.storyteller.solidcraft`). + /// Older bundle ids its Flatpak shipped under (`SolidCraft` was `ai.storyteller.solidcraft`). pub former_bundles: &'static [&'static str], /// Its website, when it isn't a page on getartcraft.com (a community app has its own). pub site: Option<&'static str>, @@ -53,31 +53,36 @@ pub struct CraftApp { impl CraftApp { /// `ai.storyteller.`: macOS bundle id, Flatpak id and Linux desktop-file id. + #[must_use] pub fn bundle_id(&self) -> String { self.bundle.map_or_else(|| format!("ai.storyteller.{}", self.id), str::to_string) } + #[must_use] pub fn releases_url(&self) -> String { format!("https://github.com/{}/releases", self.repo) } + #[must_use] pub fn repo_url(&self) -> String { format!("https://github.com/{}", self.repo) } /// The app's website: its page on getartcraft.com, or a community app's own site. + #[must_use] pub fn website(&self) -> String { self.site.map_or_else(|| format!("https://getartcraft.com/apps/{}", self.id), str::to_string) } /// Whether the launcher installs this app from a `kind` package. + #[must_use] pub fn installs(&self, kind: crate::PackageKind) -> bool { kind != crate::PackageKind::Dmg || self.mac_team.is_some() } /// Bundle ids this app may be installed under, current first. pub fn bundle_ids(&self) -> impl Iterator + '_ { - std::iter::once(self.bundle_id()).chain(self.former_bundles.iter().map(|b| b.to_string())) + std::iter::once(self.bundle_id()).chain(self.former_bundles.iter().map(ToString::to_string)) } /// Asset stems this app's releases may use, current first. @@ -90,6 +95,7 @@ impl CraftApp { std::iter::once(self.name).chain(self.former_names.iter().copied()) } + #[must_use] pub fn by_id(id: &str) -> Option<&'static CraftApp> { SUITE.iter().find(|a| a.id == id) } @@ -214,18 +220,18 @@ pub const SUITE: [CraftApp; 14] = [ }, ]; -/// The Apple Developer team that signs every official Craft App and ArtCraft Launcher (Learning +/// The Apple Developer team that signs every official Craft App and `ArtCraft` Launcher (Learning /// Machines LLC): the macOS side of the Windows publisher check. pub const ARTCRAFT_TEAM_ID: &str = "DJ6XS33FX8"; -/// ArtCraft's website. +/// `ArtCraft`'s website. pub const WEBSITE_URL: &str = "https://getartcraft.com"; /// The GitHub account every official Craft App's repository lives under. The release feed can /// only move an app within it; a community app installs from its own repo, pinned in [`SUITE`]. pub const GITHUB_OWNER: &str = "storytold"; -/// ArtCraft on GitHub: every Craft App's source. +/// `ArtCraft` on GitHub: every Craft App's source. pub const GITHUB_URL: &str = "https://github.com/storytold"; -/// ArtCraft's social accounts: (service, URL). Shown as small icons, less prominent than Discord. +/// `ArtCraft`'s social accounts: (service, URL). Shown as small icons, less prominent than Discord. pub const SOCIAL: [(&str, &str); 5] = [ ("X", "https://x.com/get_artcraft"), ("Instagram", "https://www.instagram.com/officialartcraftstudios"), @@ -234,12 +240,12 @@ pub const SOCIAL: [(&str, &str); 5] = [ ("TikTok", "https://www.tiktok.com/@artcraft.studios"), ]; -/// The ArtCraft community on Discord. +/// The `ArtCraft` community on Discord. pub const DISCORD_URL: &str = "https://discord.gg/artcraft"; -/// Deep link into the Discord application for the ArtCraft server invite. +/// Deep link into the Discord application for the `ArtCraft` server invite. pub const DISCORD_APP_URL: &str = "discord://-/invite/artcraft"; -/// ArtCraft Launcher itself, described like a Craft App so it can update itself with the same +/// `ArtCraft` Launcher itself, described like a Craft App so it can update itself with the same /// machinery (asset names `artcraft-launcher--…`, bundle id `ai.storyteller.artcraft-launcher`, /// `ArtCraft Launcher.app`). Not part of [`SUITE`]. pub const LAUNCHER: CraftApp = app( @@ -257,6 +263,7 @@ pub const LAUNCHER_ID: &str = "artcraft-launcher"; /// A Craft App's 128 px icon (PNG), as copied from its repo into `assets/app-icons`: the UI /// draws it, and the Linux install puts it in the desktop menu. +#[must_use] pub fn app_icon_png(id: &str) -> Option<&'static [u8]> { Some(match id { "photocraft" => include_bytes!("../../../assets/app-icons/photocraft.png"), diff --git a/crates/core/src/details.rs b/crates/core/src/details.rs index 3b17ef4b..e1c25df9 100644 --- a/crates/core/src/details.rs +++ b/crates/core/src/details.rs @@ -69,6 +69,7 @@ pub const MAX_SCREENSHOT_PIXELS: u64 = 8192 * 8192; /// True when `bytes` start like a JPEG file. A captive portal's login page, a proxy's error page or /// a truncated answer is refused before it is saved or decoded. +#[must_use] pub fn looks_like_jpeg(bytes: &[u8]) -> bool { bytes.starts_with(&[0xFF, 0xD8, 0xFF]) } @@ -76,8 +77,9 @@ pub fn looks_like_jpeg(bytes: &[u8]) -> bool { /// Reads the pixel dimensions `(width, height)` declared in a JPEG's frame header, without /// decoding any pixels. `None` when the bytes aren't a JPEG we can read a frame size from. /// -/// It walks the marker segments to the Start-Of-Frame (SOFn) marker, whose payload begins with +/// It walks the marker segments to the Start-Of-Frame (`SOFn`) marker, whose payload begins with /// `precision (1) · height (2, big-endian) · width (2)`. +#[must_use] pub fn jpeg_dimensions(bytes: &[u8]) -> Option<(u16, u16)> { if !looks_like_jpeg(bytes) { return None; @@ -128,6 +130,7 @@ pub fn jpeg_dimensions(bytes: &[u8]) -> Option<(u16, u16)> { /// Whether `bytes` is a JPEG whose declared dimensions are within [`MAX_SCREENSHOT_PIXELS`], so it /// is safe to hand to an image loader that allocates from the header before decoding. +#[must_use] pub fn screenshot_within_budget(bytes: &[u8]) -> bool { match jpeg_dimensions(bytes) { Some((w, h)) => w != 0 && h != 0 && u64::from(w) * u64::from(h) <= MAX_SCREENSHOT_PIXELS, @@ -494,10 +497,12 @@ pub const DETAILS: [AppDetails; 14] = [ impl AppDetails { /// Where the picture `key` of this app is published, or `None` if the page has no such picture. /// The only way to turn a request into an address: callers never build one from their own text. + #[must_use] pub fn screenshot_url(&self, key: &str) -> Option { self.shots.iter().find(|s| s.key == key).map(|s| format!("{SCREENSHOTS_BASE}/{SCREENSHOTS_REV}/{}/{}.jpg", self.id, s.key)) } + #[must_use] pub fn by_id(id: &str) -> Option<&'static AppDetails> { DETAILS.iter().find(|d| d.id == id) } diff --git a/crates/core/src/distro.rs b/crates/core/src/distro.rs index 89080522..11678d3a 100644 --- a/crates/core/src/distro.rs +++ b/crates/core/src/distro.rs @@ -16,6 +16,7 @@ pub struct OsRelease { } /// Reads `os-release` text (`KEY=value` lines, values optionally quoted). +#[must_use] pub fn parse_os_release(text: &str) -> OsRelease { let mut out = OsRelease::default(); for line in text.lines() { @@ -45,7 +46,8 @@ fn unquote(v: &str) -> &str { /// The distro's own package format: `.deb` for the Debian family, `.rpm` for the Fedora, Red Hat /// and SUSE families, `.pkg.tar.zst` for the Arch Linux family, `None` for anything else -/// (unknown distros), which gets AppImages. +/// (unknown distros), which gets `AppImage` files. +#[must_use] pub fn native_package(os: &OsRelease) -> Option { std::iter::once(&os.id).chain(&os.id_like).find_map(|id| family(id)) } diff --git a/crates/core/src/feed.rs b/crates/core/src/feed.rs index 5e66acb5..cb9175c3 100644 --- a/crates/core/src/feed.rs +++ b/crates/core/src/feed.rs @@ -142,7 +142,8 @@ impl Feed { } /// The repo to ask GitHub about for `app`, following the feed's repo renames. Always under - /// [`GITHUB_OWNER`]: the feed can move an app within ArtCraft's account, never out of it. + /// [`GITHUB_OWNER`]: the feed can move an app within `ArtCraft`'s account, never out of it. + #[must_use] pub fn repo_for(&self, app: &CraftApp) -> String { let mut repo = app.repo.to_string(); // Follow a chain of moves (a → b → c), without looping forever. @@ -156,6 +157,7 @@ impl Feed { } /// What the feed says about `app` at `now`. + #[must_use] pub fn answer(&self, app: &CraftApp, now: i64) -> FeedAnswer { let Some(entry) = self.apps.get(app.id) else { return FeedAnswer::AskGitHub }; let Some(fetched_at) = entry.fetched_at else { return FeedAnswer::AskGitHub }; @@ -232,9 +234,8 @@ fn lenient<'de, D: Deserializer<'de>, T: DeserializeOwned + Default>(d: D) -> Re /// A list where entries of the wrong shape are dropped rather than spoiling the rest. fn lenient_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(d: D) -> Result, D::Error> { let value = serde_json::Value::deserialize(d)?; - let items = match value { - serde_json::Value::Array(items) => items, - _ => return Ok(Vec::new()), + let serde_json::Value::Array(items) = value else { + return Ok(Vec::new()); }; Ok(items.into_iter().filter_map(|v| T::deserialize(v).ok()).collect()) } @@ -242,9 +243,8 @@ fn lenient_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(d: D) -> Result, T: DeserializeOwned>(d: D) -> Result, D::Error> { let value = serde_json::Value::deserialize(d)?; - let entries = match value { - serde_json::Value::Object(entries) => entries, - _ => return Ok(BTreeMap::new()), + let serde_json::Value::Object(entries) = value else { + return Ok(BTreeMap::new()); }; Ok(entries.into_iter().filter_map(|(k, v)| T::deserialize(v).ok().map(|t| (k, t))).collect()) } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index a9ab1da6..60df45a4 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,4 +1,4 @@ -//! ArtCraft Launcher core: everything that is pure data and logic. +//! `ArtCraft` Launcher core: everything that is pure data and logic. //! //! No I/O lives here, so the desktop shell, the web build and the tests share it unchanged: //! the Craft App Suite catalog, version handling, GitHub release parsing, choosing the right diff --git a/crates/core/src/platform.rs b/crates/core/src/platform.rs index 3467e579..0359c7e6 100644 --- a/crates/core/src/platform.rs +++ b/crates/core/src/platform.rs @@ -19,6 +19,7 @@ pub enum Os { } impl Os { + #[must_use] pub fn label(self) -> &'static str { match self { Self::Windows => "Windows", @@ -38,6 +39,7 @@ pub enum Arch { } impl Arch { + #[must_use] pub fn label(self) -> &'static str { match self { Self::X64 => "x64", @@ -68,6 +70,7 @@ pub enum PackageKind { } impl PackageKind { + #[must_use] pub fn label(self) -> &'static str { match self { Self::Msi => "Installer (.msi)", @@ -106,6 +109,7 @@ pub struct Platform { impl Platform { /// The platform this binary was built for, or `None` for wasm and unsupported targets. + #[must_use] pub fn current() -> Option { let os = if cfg!(target_os = "windows") { Os::Windows @@ -132,6 +136,7 @@ impl Platform { Some(Self { os, arch }) } + #[must_use] pub fn label(self) -> String { match self.os { Os::MacOs => "macOS".into(), @@ -147,21 +152,19 @@ impl Platform { (Os::Windows, Arch::X64) => &["windows-x64", "windows-x86"], (Os::Windows, Arch::X86) => &["windows-x86"], (Os::Windows, Arch::Arm64) => &["windows-arm64", "windows-x64", "windows-x86"], - (Os::Windows, _) => &[], (Os::MacOs, Arch::X64) => &["macos-universal", "macos-x86_64"], (Os::MacOs, Arch::Arm64) => &["macos-universal", "macos-aarch64", "macos-arm64", "macos-x86_64"], - (Os::MacOs, _) => &[], (Os::Linux, Arch::X64) => &["linux-x86_64"], (Os::Linux, Arch::Arm64) => &["linux-aarch64"], (Os::Linux, Arch::Riscv64) => &["linux-riscv64"], - (Os::Linux, Arch::X86) => &[], (Os::FreeBsd, Arch::X64) => &["freebsd-x86_64"], (Os::FreeBsd, Arch::Arm64) => &["freebsd-aarch64"], - (Os::FreeBsd, _) => &[], + (Os::Windows | Os::MacOs | Os::FreeBsd, _) | (Os::Linux, Arch::X86) => &[], } } /// Package formats the launcher installs on this OS, in order of preference. + #[must_use] pub fn default_kinds(self) -> &'static [PackageKind] { match self.os { Os::Windows => &[PackageKind::Msi, PackageKind::PortableZip], @@ -172,6 +175,7 @@ impl Platform { } /// Every format offered as a manual download on this OS (the web build's download menu). + #[must_use] pub fn download_kinds(self) -> &'static [PackageKind] { match self.os { Os::Windows => &[PackageKind::Msi, PackageKind::PortableZip], @@ -194,6 +198,7 @@ pub struct AssetName { impl AssetName { /// The architecture the asset is built for: the last part of its token (`windows-x86` → x86). /// `None` for a token that names none (`macos-universal`). + #[must_use] pub fn arch(&self) -> Option { match self.token.rsplit('-').next()? { "x64" | "x86_64" => Some(Arch::X64), @@ -207,6 +212,7 @@ impl AssetName { /// Reads `---[-portable].`; `None` for checksums, zsync files, CLI /// and web bundles, or anything else. +#[must_use] pub fn parse_asset_name(name: &str, stems: &[&str]) -> Option { const KINDS: [PackageKind; 9] = [ PackageKind::PortableZip, @@ -235,6 +241,7 @@ pub fn parse_asset_name(name: &str, stems: &[&str]) -> Option { /// The best asset of `release` for `platform`, trying `kinds` in order and, within a kind, the /// platform's tokens in order (native before emulated). +#[must_use] pub fn pick_asset<'a>(release: &'a Release, stems: &[&str], platform: Platform, kinds: &[PackageKind]) -> Option<(&'a Asset, PackageKind)> { let parsed: Vec<(&Asset, AssetName)> = release.assets.iter().filter_map(|a| parse_asset_name(&a.name, stems).map(|n| (a, n))).collect(); for kind in kinds { diff --git a/crates/core/src/protocol.rs b/crates/core/src/protocol.rs index c3a64dcd..4eeafb6c 100644 --- a/crates/core/src/protocol.rs +++ b/crates/core/src/protocol.rs @@ -51,7 +51,7 @@ pub enum Command { Cancel { app: String, }, - /// Download the newer ArtCraft Launcher, put it in place and restart into it. + /// Download the newer `ArtCraft` Launcher, put it in place and restart into it. UpdateLauncher, /// Fetch the pictures of an app's details page (`core::details`), one [`Event::Screenshot`] /// each, the lead picture first. Pictures already saved on this machine arrive without @@ -150,13 +150,14 @@ pub const INSTALL_CANCELLED: &str = "install cancelled"; /// Which service an app's release information came from (the footer names them). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Origin { - /// ArtCraft's release feed (storyteller-web), which polls GitHub for everyone. + /// `ArtCraft`'s release feed (storyteller-web), which polls GitHub for everyone. ArtCraftApi, /// GitHub directly: the fallback. GitHub, } impl Origin { + #[must_use] pub fn label(self) -> &'static str { match self { Self::ArtCraftApi => "ArtCraft API", @@ -168,7 +169,7 @@ impl Origin { /// Where release information came from. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum Source { - /// ArtCraft's release feed (storyteller-web), which polls GitHub for everyone. + /// `ArtCraft`'s release feed (storyteller-web), which polls GitHub for everyone. Feed, /// The GitHub REST API. GitHubApi, @@ -179,6 +180,7 @@ pub enum Source { } impl Source { + #[must_use] pub fn label(self) -> &'static str { match self { Self::Feed => "ArtCraft", @@ -203,11 +205,11 @@ pub enum Event { app: String, result: Result, String>, }, - /// The latest ArtCraft Launcher release, when it's newer than this one. + /// The latest `ArtCraft` Launcher release, when it's newer than this one. LauncherUpdate(Release), /// The new launcher is in place (or will be, once this one exits): quit now so it can start. LauncherRestarting, - /// News and alerts from ArtCraft's release feed (replaces any earlier set). + /// News and alerts from `ArtCraft`'s release feed (replaces any earlier set). Notices { announcements: Vec, alerts: Vec, diff --git a/crates/core/src/release.rs b/crates/core/src/release.rs index f599b999..9d857a2d 100644 --- a/crates/core/src/release.rs +++ b/crates/core/src/release.rs @@ -49,6 +49,7 @@ impl Release { } } + #[must_use] pub fn sums_asset(&self) -> Option<&Asset> { self.assets.iter().find(|a| a.name == "SHA256SUMS.txt") } @@ -81,6 +82,7 @@ pub fn safe_web_link(url: &str) -> bool { /// Characters a command interpreter (POSIX shells or `cmd.exe`) may treat specially. A real /// `https` URL never needs any of them unescaped in a browser-opened link. `%` matters because /// `cmd.exe` expands `%NAME%` references, and an expanded value could itself carry metacharacters. +#[must_use] pub fn is_shell_meta(c: char) -> bool { matches!(c, '|' | '&' | ';' | '<' | '>' | '(' | ')' | '$' | '`' | '"' | '\'' | '^' | '!' | '*' | '%' | '{' | '}' | '[' | ']') } @@ -89,6 +91,7 @@ pub fn is_shell_meta(c: char) -> bool { /// starts with `https://github.com//releases`, contains no dot-segments (`.` or `..`), /// no percent-encoded path separators (`%2f`, `%5c`), no query/fragment/backslash, and /// satisfies [`safe_web_link`] (no shell metacharacters or control bytes, CWE-78). +#[must_use] pub fn safe_release_html_url(repo: &str, url: &str) -> Option { if !safe_web_link(url) { return None; @@ -111,6 +114,7 @@ pub fn safe_release_html_url(repo: &str, url: &str) -> Option { } /// The prefix every download of `repo` must start with. +#[must_use] pub fn download_prefix(repo: &str) -> String { format!("https://github.com/{repo}/releases/download/") } @@ -123,12 +127,14 @@ pub fn download_prefix(repo: &str) -> String { /// accepted only when the text after the prefix is exactly `/` — two non-empty path /// segments with no traversal (`.`/`..`), no additional slashes, no query or fragment, and no /// backslash or percent-encoded separators that a client could later re-interpret. +#[must_use] pub fn download_url_under(url: &str, prefix: &str) -> bool { let Some(rest) = url.strip_prefix(prefix) else { return false }; download_suffix_ok(rest) } /// Whether `url` sits under a developer mirror `base` (ending in `/`) without escaping it. +#[must_use] pub fn download_url_under_mirror(url: &str, base: &str) -> bool { let Some(rest) = url.strip_prefix(base) else { return false }; // A mirror serves `/` just like GitHub, but we only require that it can't climb out @@ -159,6 +165,10 @@ fn contains_encoded_separator(rest: &str) -> bool { } /// Reads `GET /repos//releases/latest` (or one element of `/releases`). +/// +/// # Errors +/// +/// Returns an error if the JSON is malformed or does not describe a usable release. pub fn parse_github_release(json: &str, repo: &str) -> Result { let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?; release_from_value(&v, repo) @@ -166,6 +176,10 @@ pub fn parse_github_release(json: &str, repo: &str) -> Result { /// Published releases offered for manual selection, in GitHub's order. /// Drafts and unparseable tags cannot be installed. +/// +/// # Errors +/// +/// Returns an error if the JSON is malformed or its top level is not an array. pub fn parse_github_versions(json: &str, repo: &str) -> Result, String> { let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?; let list = v.as_array().ok_or("unexpected answer from GitHub")?; @@ -179,15 +193,18 @@ pub fn parse_github_versions(json: &str, repo: &str) -> Result, Str } /// A published, explicitly marked nightly build, not merely a beta or release candidate. +#[must_use] pub fn is_nightly(release: &Release) -> bool { release.prerelease && release.version.as_ref().is_some_and(|v| v.pre.as_str().split('.').any(|part| part.eq_ignore_ascii_case("nightly"))) } /// Selects a published release. A nightly must be explicitly marked; a pin never falls back. +#[must_use] pub fn has_published_checksum(r: &Release) -> bool { r.sums_asset().is_some() || r.assets.iter().any(|a| a.sha256.is_some()) } +#[must_use] pub fn choose_version(releases: &[Release], track: &crate::protocol::VersionTrack) -> Option { use crate::protocol::VersionTrack; match track { @@ -203,6 +220,10 @@ pub fn choose_version(releases: &[Release], track: &crate::protocol::VersionTrac /// Reads `GET /repos//releases` and returns the newest stable (or any, with /// `allow_prerelease`) published release. +/// +/// # Errors +/// +/// Returns an error if the JSON is malformed or its top level is not an array. pub fn parse_github_release_list(json: &str, repo: &str, allow_prerelease: bool) -> Result, String> { let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?; let list = v.as_array().ok_or("unexpected answer from GitHub")?; @@ -262,6 +283,7 @@ fn release_from_value(v: &serde_json::Value, repo: &str) -> Result Release { let prefix = download_prefix(repo); let mut assets: Vec = sums @@ -282,12 +304,14 @@ pub fn release_from_sums(repo: &str, tag: &str, sums: &[(String, String)]) -> Re } /// The tag in a `https://github.com//releases/tag/` redirect target. +#[must_use] pub fn tag_from_redirect(location: &str, repo: &str) -> Option { let rest = location.strip_prefix(&format!("https://github.com/{repo}/releases/tag/"))?; (!rest.is_empty() && rest.len() <= 64 && rest.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-+".contains(&b))).then(|| rest.to_string()) } /// Reads `sha256sum` output: ` ` (or ` *`) per line. +#[must_use] pub fn parse_sha256sums(text: &str) -> Vec<(String, String)> { text.lines() .filter_map(|line| { @@ -299,6 +323,7 @@ pub fn parse_sha256sums(text: &str) -> Vec<(String, String)> { } /// A bare file name we'd be willing to save: no paths, no control characters. +#[must_use] pub fn valid_file_name(name: &str) -> bool { !name.is_empty() && name.len() <= 200 diff --git a/crates/core/src/status.rs b/crates/core/src/status.rs index 03876852..966ce721 100644 --- a/crates/core/src/status.rs +++ b/crates/core/src/status.rs @@ -22,13 +22,14 @@ pub enum InstallSource { Pacman, /// A Flatpak. Flatpak, - /// An AppImage file found on disk. + /// An `AppImage` file found on disk. AppImage, /// A binary found on `PATH` or in a system prefix. Binary, } impl InstallSource { + #[must_use] pub fn label(self) -> &'static str { match self { Self::Launcher => "ArtCraft Launcher", @@ -45,6 +46,7 @@ impl InstallSource { /// Whether the launcher may replace or remove this copy itself. Packages owned by a system /// package manager (deb, rpm, Flatpak) are updated through that manager instead. + #[must_use] pub fn launcher_can_update(self) -> bool { matches!(self, Self::Launcher | Self::MacApp | Self::Msi | Self::AppImage) } @@ -56,7 +58,7 @@ pub struct Installed { /// `None` when the copy is there but its version couldn't be read. pub version: Option, pub source: InstallSource, - /// Where it lives: the `.app`, the exe, the AppImage, or the binary of a package. + /// Where it lives: the `.app`, the exe, the `AppImage`, or the binary of a package. pub location: String, /// The package that installed it, for package-manager installs (`photocraft-bin`). #[serde(default)] @@ -83,6 +85,7 @@ pub enum AppStatus { } impl AppStatus { + #[must_use] pub fn is_installed(&self) -> bool { matches!(self, Self::UpToDate | Self::UpdateAvailable | Self::Installed) } @@ -97,6 +100,7 @@ pub enum Latest<'a> { Found { version: Option<&'a Version>, has_asset: bool }, } +#[must_use] pub fn status(installed: Option<&Installed>, latest: Latest<'_>) -> AppStatus { match (installed, latest) { (None, Latest::Pending) => AppStatus::Checking, diff --git a/crates/core/src/time.rs b/crates/core/src/time.rs index 347fe3df..2acfe81b 100644 --- a/crates/core/src/time.rs +++ b/crates/core/src/time.rs @@ -35,37 +35,38 @@ pub enum TimeAgo { } /// Seconds since the Unix epoch for an RFC 3339 UTC timestamp such as `2026-10-08T14:52:50Z`. +#[must_use] pub fn parse_rfc3339(text: &str) -> Option { - let b = text.trim().as_bytes(); - if b.len() < 19 || b.get(4) != Some(&b'-') || b.get(7) != Some(&b'-') || !matches!(b.get(10), Some(b'T' | b't' | b' ')) { + let bytes = text.trim().as_bytes(); + if bytes.len() < 19 || bytes.get(4) != Some(&b'-') || bytes.get(7) != Some(&b'-') || !matches!(bytes.get(10), Some(b'T' | b't' | b' ')) { return None; } let num = |from: usize, to: usize| -> Option { - let s = std::str::from_utf8(b.get(from..to)?).ok()?; - if !s.bytes().all(|c| c.is_ascii_digit()) { + let slice = std::str::from_utf8(bytes.get(from..to)?).ok()?; + if !slice.bytes().all(|c| c.is_ascii_digit()) { return None; } - s.parse().ok() + slice.parse().ok() }; - let (y, mo, d) = (num(0, 4)?, num(5, 7)?, num(8, 10)?); - let (h, mi, s) = (num(11, 13)?, num(14, 16)?, num(17, 19)?); - if !(1..=12).contains(&mo) || !(1..=31).contains(&d) || h > 23 || mi > 59 || s > 60 { + let (year, month, day) = (num(0, 4)?, num(5, 7)?, num(8, 10)?); + let (hour, minute, second) = (num(11, 13)?, num(14, 16)?, num(17, 19)?); + if !(1..=12).contains(&month) || !(1..=31).contains(&day) || hour > 23 || minute > 59 || second > 60 { return None; } // Offsets other than Z: GitHub always sends Z, but honour ±hh:mm if present. - let tail = std::str::from_utf8(b.get(19..)?).ok()?; + let tail = std::str::from_utf8(bytes.get(19..)?).ok()?; let tail = tail.strip_prefix('.').map_or(tail, |t| t.trim_start_matches(|c: char| c.is_ascii_digit())); let offset = match tail { "" | "Z" | "z" => 0, t if t.len() == 6 && (t.starts_with('+') || t.starts_with('-')) => { let sign = if t.starts_with('-') { -1 } else { 1 }; - let oh: i64 = t.get(1..3)?.parse().ok()?; - let om: i64 = t.get(4..6)?.parse().ok()?; - sign * (oh * 3600 + om * 60) + let offset_hours: i64 = t.get(1..3)?.parse().ok()?; + let offset_minutes: i64 = t.get(4..6)?.parse().ok()?; + sign * (offset_hours * 3600 + offset_minutes * 60) } _ => return None, }; - Some(days_from_civil(y, mo, d)? * 86_400 + h * 3600 + mi * 60 + s - offset) + Some(days_from_civil(year, month, day)? * 86_400 + hour * 3600 + minute * 60 + second - offset) } /// Days since 1970-01-01 (through jiff's civil calendar). A day past the month's length rolls over @@ -78,11 +79,12 @@ fn days_from_civil(y: i64, m: i64, d: i64) -> Option { } /// (year, month, day) for a Unix time (UTC). jiff's civil calendar only spans years -9999..=9999, -/// far narrower than the whole `i64` the old hand-rolled Hinnant code converted, so the instant is +/// far narrower than the whole `i64` the old hand-rolled `Hinnant` code converted, so the instant is /// first moved into range by whole 400-year Gregorian cycles (the calendar repeats every 400 years -/// = 146_097 days) and the real year restored afterwards. jiff still does the month/day; the cycle +/// = `146_097` days) and the real year restored afterwards. jiff still does the month/day; the cycle /// count only shifts the year, keeping every `i64` exact (e.g. `i64::MAX` → year 292277026596, /// `i64::MIN` → year -292277022657), with no epoch fallback for a value the old code converted. +#[must_use] pub fn civil_from_unix(secs: i64) -> (i64, u32, u32) { let epoch = jiff::civil::Date::constant(1970, 1, 1); let days = secs.div_euclid(86_400); @@ -101,11 +103,13 @@ const MONTHS: [&str; 12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Au /// English three-letter month abbreviation for month `m` (1–12); `"?"` when out of range. /// Source key for `tr_ctx("month", …)` at the call site; never shown untranslated in /// non-English UI. +#[must_use] pub fn month_short_en(m: u32) -> &'static str { if (1..=12).contains(&m) { MONTHS.get((m - 1) as usize).copied().unwrap_or("?") } else { "?" } } /// `Oct 8, 2026` +#[must_use] pub fn format_date(secs: i64) -> String { let (y, m, d) = civil_from_unix(secs); let month = month_short_en(m); @@ -115,6 +119,7 @@ pub fn format_date(secs: i64) -> String { /// Classify a timestamp for translation-neutral rendering (no allocation, no English). /// Thresholds match [`format_ago`]: <60s → [`TimeAgo::JustNow`], <1h → minutes, /// <1d → hours, <2d → yesterday, <30d → days, older → [`TimeAgo::Date`]. +#[must_use] pub fn ago_kind(secs: i64, now: i64) -> TimeAgo { let dt = now.saturating_sub(secs); if dt < 60 { @@ -135,6 +140,7 @@ pub fn ago_kind(secs: i64, now: i64) -> TimeAgo { /// `just now`, `5 min ago`, `3 h ago`, `yesterday`, `4 days ago`, or the date. /// /// English-only fallback; translatable UI should match on [`ago_kind`] instead. +#[must_use] pub fn format_ago(secs: i64, now: i64) -> String { match ago_kind(secs, now) { TimeAgo::JustNow => "just now".into(), diff --git a/crates/core/src/version.rs b/crates/core/src/version.rs index 0beceef1..cb649a1d 100644 --- a/crates/core/src/version.rs +++ b/crates/core/src/version.rs @@ -8,6 +8,7 @@ pub use semver::Version; /// /// Accepts `v0.5.0`, `0.5.0`, `0.2.0-rc.1`, Debian's `0.2.0~rc.1-1`, and the two-part `0.5` /// some platforms report. Build metadata is kept but never affects ordering. +#[must_use] pub fn parse(text: &str) -> Option { let t = text.trim(); let t = t.strip_prefix(['v', 'V']).unwrap_or(t); @@ -35,6 +36,7 @@ pub fn parse(text: &str) -> Option { /// Reads a version as a system package manager reports it, dropping what the packaging adds: /// an epoch (`1:`), the package revision (`-1`, `-2.fc40`), Debian's `~` pre-release spelling, and /// a VCS snapshot suffix (`0.3.0.r47.g47f9306` from an AUR `-git` package, read as `0.3.0`). +#[must_use] pub fn parse_package(text: &str) -> Option { let t = text.trim(); // Epoch. @@ -98,23 +100,27 @@ fn digits(text: &str, from: usize) -> Option<(u64, usize)> { } /// A version that's a plain `X.Y.Z` with no pre-release suffix. +#[must_use] pub fn is_stable(v: &Version) -> bool { v.pre.is_empty() } /// Orders by precedence, ignoring build metadata. +#[must_use] pub fn compare(a: &Version, b: &Version) -> Ordering { a.cmp_precedence(b) } /// True when `latest` is newer than `installed`. +#[must_use] pub fn is_newer(latest: &Version, installed: &Version) -> bool { compare(latest, installed) == Ordering::Greater } -/// Platforms that only record `X.Y.Z` (the MSI ProductVersion, `CFBundleShortVersionString`) +/// Platforms that only record `X.Y.Z` (the MSI `ProductVersion`, `CFBundleShortVersionString`) /// drop a pre-release suffix. A numeric-only installed version therefore counts as current when it /// matches a pre-release's numbers, rather than nagging forever. +#[must_use] pub fn is_update(latest: &Version, installed: &Version) -> bool { if installed.pre.is_empty() && !latest.pre.is_empty() From 6ec5bba91b49196859a1835eb66a4cdaad0e598f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Legrand?= Date: Sun, 1 Nov 2026 23:01:57 +0100 Subject: [PATCH 2/2] style(core): remove review churn --- crates/core/src/catalog.rs | 25 +++++++++---------------- crates/core/src/details.rs | 5 ----- crates/core/src/distro.rs | 2 -- crates/core/src/feed.rs | 4 +--- crates/core/src/lib.rs | 2 +- crates/core/src/platform.rs | 10 ---------- crates/core/src/protocol.rs | 12 +++++------- crates/core/src/release.rs | 13 ------------- crates/core/src/status.rs | 4 ---- crates/core/src/time.rs | 6 ------ crates/core/src/version.rs | 6 ------ 11 files changed, 16 insertions(+), 73 deletions(-) diff --git a/crates/core/src/catalog.rs b/crates/core/src/catalog.rs index 1f92204e..c45dc070 100644 --- a/crates/core/src/catalog.rs +++ b/crates/core/src/catalog.rs @@ -6,7 +6,7 @@ //! keyed by the app id (`tr_ctx(app.id, app.tagline)` in `ui-egui`). /// Who makes an app. Official apps live under [`GITHUB_OWNER`]; a community app is maintained -/// outside `ArtCraft` and is labelled as such wherever it is shown. +/// outside ArtCraft and is labelled as such wherever it is shown. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum AppKind { Official, @@ -37,7 +37,7 @@ pub struct CraftApp { pub kind: AppKind, /// Who publishes it, as the card's byline shows it (`ArtCraft`, `Tangency Labs`). pub publisher: &'static str, - /// The publisher its Windows installer names, when it isn't `ArtCraft`'s (`Learning Machines LLC`). + /// The publisher its Windows installer names, when it isn't ArtCraft's (`Learning Machines LLC`). pub msi_publisher: Option<&'static str>, /// The bundle id when it isn't `ai.storyteller.` (a community app brings its own). pub bundle: Option<&'static str>, @@ -53,29 +53,24 @@ pub struct CraftApp { impl CraftApp { /// `ai.storyteller.`: macOS bundle id, Flatpak id and Linux desktop-file id. - #[must_use] pub fn bundle_id(&self) -> String { self.bundle.map_or_else(|| format!("ai.storyteller.{}", self.id), str::to_string) } - #[must_use] pub fn releases_url(&self) -> String { format!("https://github.com/{}/releases", self.repo) } - #[must_use] pub fn repo_url(&self) -> String { format!("https://github.com/{}", self.repo) } /// The app's website: its page on getartcraft.com, or a community app's own site. - #[must_use] pub fn website(&self) -> String { self.site.map_or_else(|| format!("https://getartcraft.com/apps/{}", self.id), str::to_string) } /// Whether the launcher installs this app from a `kind` package. - #[must_use] pub fn installs(&self, kind: crate::PackageKind) -> bool { kind != crate::PackageKind::Dmg || self.mac_team.is_some() } @@ -95,7 +90,6 @@ impl CraftApp { std::iter::once(self.name).chain(self.former_names.iter().copied()) } - #[must_use] pub fn by_id(id: &str) -> Option<&'static CraftApp> { SUITE.iter().find(|a| a.id == id) } @@ -220,18 +214,18 @@ pub const SUITE: [CraftApp; 14] = [ }, ]; -/// The Apple Developer team that signs every official Craft App and `ArtCraft` Launcher (Learning +/// The Apple Developer team that signs every official Craft App and ArtCraft Launcher (Learning /// Machines LLC): the macOS side of the Windows publisher check. pub const ARTCRAFT_TEAM_ID: &str = "DJ6XS33FX8"; -/// `ArtCraft`'s website. +/// ArtCraft's website. pub const WEBSITE_URL: &str = "https://getartcraft.com"; /// The GitHub account every official Craft App's repository lives under. The release feed can /// only move an app within it; a community app installs from its own repo, pinned in [`SUITE`]. pub const GITHUB_OWNER: &str = "storytold"; -/// `ArtCraft` on GitHub: every Craft App's source. +/// ArtCraft on GitHub: every Craft App's source. pub const GITHUB_URL: &str = "https://github.com/storytold"; -/// `ArtCraft`'s social accounts: (service, URL). Shown as small icons, less prominent than Discord. +/// ArtCraft's social accounts: (service, URL). Shown as small icons, less prominent than Discord. pub const SOCIAL: [(&str, &str); 5] = [ ("X", "https://x.com/get_artcraft"), ("Instagram", "https://www.instagram.com/officialartcraftstudios"), @@ -240,12 +234,12 @@ pub const SOCIAL: [(&str, &str); 5] = [ ("TikTok", "https://www.tiktok.com/@artcraft.studios"), ]; -/// The `ArtCraft` community on Discord. +/// The ArtCraft community on Discord. pub const DISCORD_URL: &str = "https://discord.gg/artcraft"; -/// Deep link into the Discord application for the `ArtCraft` server invite. +/// Deep link into the Discord application for the ArtCraft server invite. pub const DISCORD_APP_URL: &str = "discord://-/invite/artcraft"; -/// `ArtCraft` Launcher itself, described like a Craft App so it can update itself with the same +/// ArtCraft Launcher itself, described like a Craft App so it can update itself with the same /// machinery (asset names `artcraft-launcher--…`, bundle id `ai.storyteller.artcraft-launcher`, /// `ArtCraft Launcher.app`). Not part of [`SUITE`]. pub const LAUNCHER: CraftApp = app( @@ -263,7 +257,6 @@ pub const LAUNCHER_ID: &str = "artcraft-launcher"; /// A Craft App's 128 px icon (PNG), as copied from its repo into `assets/app-icons`: the UI /// draws it, and the Linux install puts it in the desktop menu. -#[must_use] pub fn app_icon_png(id: &str) -> Option<&'static [u8]> { Some(match id { "photocraft" => include_bytes!("../../../assets/app-icons/photocraft.png"), diff --git a/crates/core/src/details.rs b/crates/core/src/details.rs index e1c25df9..5b06c616 100644 --- a/crates/core/src/details.rs +++ b/crates/core/src/details.rs @@ -69,7 +69,6 @@ pub const MAX_SCREENSHOT_PIXELS: u64 = 8192 * 8192; /// True when `bytes` start like a JPEG file. A captive portal's login page, a proxy's error page or /// a truncated answer is refused before it is saved or decoded. -#[must_use] pub fn looks_like_jpeg(bytes: &[u8]) -> bool { bytes.starts_with(&[0xFF, 0xD8, 0xFF]) } @@ -79,7 +78,6 @@ pub fn looks_like_jpeg(bytes: &[u8]) -> bool { /// /// It walks the marker segments to the Start-Of-Frame (`SOFn`) marker, whose payload begins with /// `precision (1) · height (2, big-endian) · width (2)`. -#[must_use] pub fn jpeg_dimensions(bytes: &[u8]) -> Option<(u16, u16)> { if !looks_like_jpeg(bytes) { return None; @@ -130,7 +128,6 @@ pub fn jpeg_dimensions(bytes: &[u8]) -> Option<(u16, u16)> { /// Whether `bytes` is a JPEG whose declared dimensions are within [`MAX_SCREENSHOT_PIXELS`], so it /// is safe to hand to an image loader that allocates from the header before decoding. -#[must_use] pub fn screenshot_within_budget(bytes: &[u8]) -> bool { match jpeg_dimensions(bytes) { Some((w, h)) => w != 0 && h != 0 && u64::from(w) * u64::from(h) <= MAX_SCREENSHOT_PIXELS, @@ -497,12 +494,10 @@ pub const DETAILS: [AppDetails; 14] = [ impl AppDetails { /// Where the picture `key` of this app is published, or `None` if the page has no such picture. /// The only way to turn a request into an address: callers never build one from their own text. - #[must_use] pub fn screenshot_url(&self, key: &str) -> Option { self.shots.iter().find(|s| s.key == key).map(|s| format!("{SCREENSHOTS_BASE}/{SCREENSHOTS_REV}/{}/{}.jpg", self.id, s.key)) } - #[must_use] pub fn by_id(id: &str) -> Option<&'static AppDetails> { DETAILS.iter().find(|d| d.id == id) } diff --git a/crates/core/src/distro.rs b/crates/core/src/distro.rs index 11678d3a..8ec1c2c4 100644 --- a/crates/core/src/distro.rs +++ b/crates/core/src/distro.rs @@ -16,7 +16,6 @@ pub struct OsRelease { } /// Reads `os-release` text (`KEY=value` lines, values optionally quoted). -#[must_use] pub fn parse_os_release(text: &str) -> OsRelease { let mut out = OsRelease::default(); for line in text.lines() { @@ -47,7 +46,6 @@ fn unquote(v: &str) -> &str { /// The distro's own package format: `.deb` for the Debian family, `.rpm` for the Fedora, Red Hat /// and SUSE families, `.pkg.tar.zst` for the Arch Linux family, `None` for anything else /// (unknown distros), which gets `AppImage` files. -#[must_use] pub fn native_package(os: &OsRelease) -> Option { std::iter::once(&os.id).chain(&os.id_like).find_map(|id| family(id)) } diff --git a/crates/core/src/feed.rs b/crates/core/src/feed.rs index cb9175c3..5b9f9036 100644 --- a/crates/core/src/feed.rs +++ b/crates/core/src/feed.rs @@ -142,8 +142,7 @@ impl Feed { } /// The repo to ask GitHub about for `app`, following the feed's repo renames. Always under - /// [`GITHUB_OWNER`]: the feed can move an app within `ArtCraft`'s account, never out of it. - #[must_use] + /// [`GITHUB_OWNER`]: the feed can move an app within ArtCraft's account, never out of it. pub fn repo_for(&self, app: &CraftApp) -> String { let mut repo = app.repo.to_string(); // Follow a chain of moves (a → b → c), without looping forever. @@ -157,7 +156,6 @@ impl Feed { } /// What the feed says about `app` at `now`. - #[must_use] pub fn answer(&self, app: &CraftApp, now: i64) -> FeedAnswer { let Some(entry) = self.apps.get(app.id) else { return FeedAnswer::AskGitHub }; let Some(fetched_at) = entry.fetched_at else { return FeedAnswer::AskGitHub }; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 60df45a4..a9ab1da6 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,4 +1,4 @@ -//! `ArtCraft` Launcher core: everything that is pure data and logic. +//! ArtCraft Launcher core: everything that is pure data and logic. //! //! No I/O lives here, so the desktop shell, the web build and the tests share it unchanged: //! the Craft App Suite catalog, version handling, GitHub release parsing, choosing the right diff --git a/crates/core/src/platform.rs b/crates/core/src/platform.rs index 0359c7e6..645e6f40 100644 --- a/crates/core/src/platform.rs +++ b/crates/core/src/platform.rs @@ -19,7 +19,6 @@ pub enum Os { } impl Os { - #[must_use] pub fn label(self) -> &'static str { match self { Self::Windows => "Windows", @@ -39,7 +38,6 @@ pub enum Arch { } impl Arch { - #[must_use] pub fn label(self) -> &'static str { match self { Self::X64 => "x64", @@ -70,7 +68,6 @@ pub enum PackageKind { } impl PackageKind { - #[must_use] pub fn label(self) -> &'static str { match self { Self::Msi => "Installer (.msi)", @@ -109,7 +106,6 @@ pub struct Platform { impl Platform { /// The platform this binary was built for, or `None` for wasm and unsupported targets. - #[must_use] pub fn current() -> Option { let os = if cfg!(target_os = "windows") { Os::Windows @@ -136,7 +132,6 @@ impl Platform { Some(Self { os, arch }) } - #[must_use] pub fn label(self) -> String { match self.os { Os::MacOs => "macOS".into(), @@ -164,7 +159,6 @@ impl Platform { } /// Package formats the launcher installs on this OS, in order of preference. - #[must_use] pub fn default_kinds(self) -> &'static [PackageKind] { match self.os { Os::Windows => &[PackageKind::Msi, PackageKind::PortableZip], @@ -175,7 +169,6 @@ impl Platform { } /// Every format offered as a manual download on this OS (the web build's download menu). - #[must_use] pub fn download_kinds(self) -> &'static [PackageKind] { match self.os { Os::Windows => &[PackageKind::Msi, PackageKind::PortableZip], @@ -198,7 +191,6 @@ pub struct AssetName { impl AssetName { /// The architecture the asset is built for: the last part of its token (`windows-x86` → x86). /// `None` for a token that names none (`macos-universal`). - #[must_use] pub fn arch(&self) -> Option { match self.token.rsplit('-').next()? { "x64" | "x86_64" => Some(Arch::X64), @@ -212,7 +204,6 @@ impl AssetName { /// Reads `---[-portable].`; `None` for checksums, zsync files, CLI /// and web bundles, or anything else. -#[must_use] pub fn parse_asset_name(name: &str, stems: &[&str]) -> Option { const KINDS: [PackageKind; 9] = [ PackageKind::PortableZip, @@ -241,7 +232,6 @@ pub fn parse_asset_name(name: &str, stems: &[&str]) -> Option { /// The best asset of `release` for `platform`, trying `kinds` in order and, within a kind, the /// platform's tokens in order (native before emulated). -#[must_use] pub fn pick_asset<'a>(release: &'a Release, stems: &[&str], platform: Platform, kinds: &[PackageKind]) -> Option<(&'a Asset, PackageKind)> { let parsed: Vec<(&Asset, AssetName)> = release.assets.iter().filter_map(|a| parse_asset_name(&a.name, stems).map(|n| (a, n))).collect(); for kind in kinds { diff --git a/crates/core/src/protocol.rs b/crates/core/src/protocol.rs index 4eeafb6c..c3a64dcd 100644 --- a/crates/core/src/protocol.rs +++ b/crates/core/src/protocol.rs @@ -51,7 +51,7 @@ pub enum Command { Cancel { app: String, }, - /// Download the newer `ArtCraft` Launcher, put it in place and restart into it. + /// Download the newer ArtCraft Launcher, put it in place and restart into it. UpdateLauncher, /// Fetch the pictures of an app's details page (`core::details`), one [`Event::Screenshot`] /// each, the lead picture first. Pictures already saved on this machine arrive without @@ -150,14 +150,13 @@ pub const INSTALL_CANCELLED: &str = "install cancelled"; /// Which service an app's release information came from (the footer names them). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Origin { - /// `ArtCraft`'s release feed (storyteller-web), which polls GitHub for everyone. + /// ArtCraft's release feed (storyteller-web), which polls GitHub for everyone. ArtCraftApi, /// GitHub directly: the fallback. GitHub, } impl Origin { - #[must_use] pub fn label(self) -> &'static str { match self { Self::ArtCraftApi => "ArtCraft API", @@ -169,7 +168,7 @@ impl Origin { /// Where release information came from. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum Source { - /// `ArtCraft`'s release feed (storyteller-web), which polls GitHub for everyone. + /// ArtCraft's release feed (storyteller-web), which polls GitHub for everyone. Feed, /// The GitHub REST API. GitHubApi, @@ -180,7 +179,6 @@ pub enum Source { } impl Source { - #[must_use] pub fn label(self) -> &'static str { match self { Self::Feed => "ArtCraft", @@ -205,11 +203,11 @@ pub enum Event { app: String, result: Result, String>, }, - /// The latest `ArtCraft` Launcher release, when it's newer than this one. + /// The latest ArtCraft Launcher release, when it's newer than this one. LauncherUpdate(Release), /// The new launcher is in place (or will be, once this one exits): quit now so it can start. LauncherRestarting, - /// News and alerts from `ArtCraft`'s release feed (replaces any earlier set). + /// News and alerts from ArtCraft's release feed (replaces any earlier set). Notices { announcements: Vec, alerts: Vec, diff --git a/crates/core/src/release.rs b/crates/core/src/release.rs index 9d857a2d..4bd4ec91 100644 --- a/crates/core/src/release.rs +++ b/crates/core/src/release.rs @@ -49,7 +49,6 @@ impl Release { } } - #[must_use] pub fn sums_asset(&self) -> Option<&Asset> { self.assets.iter().find(|a| a.name == "SHA256SUMS.txt") } @@ -82,7 +81,6 @@ pub fn safe_web_link(url: &str) -> bool { /// Characters a command interpreter (POSIX shells or `cmd.exe`) may treat specially. A real /// `https` URL never needs any of them unescaped in a browser-opened link. `%` matters because /// `cmd.exe` expands `%NAME%` references, and an expanded value could itself carry metacharacters. -#[must_use] pub fn is_shell_meta(c: char) -> bool { matches!(c, '|' | '&' | ';' | '<' | '>' | '(' | ')' | '$' | '`' | '"' | '\'' | '^' | '!' | '*' | '%' | '{' | '}' | '[' | ']') } @@ -91,7 +89,6 @@ pub fn is_shell_meta(c: char) -> bool { /// starts with `https://github.com//releases`, contains no dot-segments (`.` or `..`), /// no percent-encoded path separators (`%2f`, `%5c`), no query/fragment/backslash, and /// satisfies [`safe_web_link`] (no shell metacharacters or control bytes, CWE-78). -#[must_use] pub fn safe_release_html_url(repo: &str, url: &str) -> Option { if !safe_web_link(url) { return None; @@ -114,7 +111,6 @@ pub fn safe_release_html_url(repo: &str, url: &str) -> Option { } /// The prefix every download of `repo` must start with. -#[must_use] pub fn download_prefix(repo: &str) -> String { format!("https://github.com/{repo}/releases/download/") } @@ -127,14 +123,12 @@ pub fn download_prefix(repo: &str) -> String { /// accepted only when the text after the prefix is exactly `/` — two non-empty path /// segments with no traversal (`.`/`..`), no additional slashes, no query or fragment, and no /// backslash or percent-encoded separators that a client could later re-interpret. -#[must_use] pub fn download_url_under(url: &str, prefix: &str) -> bool { let Some(rest) = url.strip_prefix(prefix) else { return false }; download_suffix_ok(rest) } /// Whether `url` sits under a developer mirror `base` (ending in `/`) without escaping it. -#[must_use] pub fn download_url_under_mirror(url: &str, base: &str) -> bool { let Some(rest) = url.strip_prefix(base) else { return false }; // A mirror serves `/` just like GitHub, but we only require that it can't climb out @@ -193,18 +187,15 @@ pub fn parse_github_versions(json: &str, repo: &str) -> Result, Str } /// A published, explicitly marked nightly build, not merely a beta or release candidate. -#[must_use] pub fn is_nightly(release: &Release) -> bool { release.prerelease && release.version.as_ref().is_some_and(|v| v.pre.as_str().split('.').any(|part| part.eq_ignore_ascii_case("nightly"))) } /// Selects a published release. A nightly must be explicitly marked; a pin never falls back. -#[must_use] pub fn has_published_checksum(r: &Release) -> bool { r.sums_asset().is_some() || r.assets.iter().any(|a| a.sha256.is_some()) } -#[must_use] pub fn choose_version(releases: &[Release], track: &crate::protocol::VersionTrack) -> Option { use crate::protocol::VersionTrack; match track { @@ -283,7 +274,6 @@ fn release_from_value(v: &serde_json::Value, repo: &str) -> Result Release { let prefix = download_prefix(repo); let mut assets: Vec = sums @@ -304,14 +294,12 @@ pub fn release_from_sums(repo: &str, tag: &str, sums: &[(String, String)]) -> Re } /// The tag in a `https://github.com//releases/tag/` redirect target. -#[must_use] pub fn tag_from_redirect(location: &str, repo: &str) -> Option { let rest = location.strip_prefix(&format!("https://github.com/{repo}/releases/tag/"))?; (!rest.is_empty() && rest.len() <= 64 && rest.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-+".contains(&b))).then(|| rest.to_string()) } /// Reads `sha256sum` output: ` ` (or ` *`) per line. -#[must_use] pub fn parse_sha256sums(text: &str) -> Vec<(String, String)> { text.lines() .filter_map(|line| { @@ -323,7 +311,6 @@ pub fn parse_sha256sums(text: &str) -> Vec<(String, String)> { } /// A bare file name we'd be willing to save: no paths, no control characters. -#[must_use] pub fn valid_file_name(name: &str) -> bool { !name.is_empty() && name.len() <= 200 diff --git a/crates/core/src/status.rs b/crates/core/src/status.rs index 966ce721..ac646970 100644 --- a/crates/core/src/status.rs +++ b/crates/core/src/status.rs @@ -29,7 +29,6 @@ pub enum InstallSource { } impl InstallSource { - #[must_use] pub fn label(self) -> &'static str { match self { Self::Launcher => "ArtCraft Launcher", @@ -46,7 +45,6 @@ impl InstallSource { /// Whether the launcher may replace or remove this copy itself. Packages owned by a system /// package manager (deb, rpm, Flatpak) are updated through that manager instead. - #[must_use] pub fn launcher_can_update(self) -> bool { matches!(self, Self::Launcher | Self::MacApp | Self::Msi | Self::AppImage) } @@ -85,7 +83,6 @@ pub enum AppStatus { } impl AppStatus { - #[must_use] pub fn is_installed(&self) -> bool { matches!(self, Self::UpToDate | Self::UpdateAvailable | Self::Installed) } @@ -100,7 +97,6 @@ pub enum Latest<'a> { Found { version: Option<&'a Version>, has_asset: bool }, } -#[must_use] pub fn status(installed: Option<&Installed>, latest: Latest<'_>) -> AppStatus { match (installed, latest) { (None, Latest::Pending) => AppStatus::Checking, diff --git a/crates/core/src/time.rs b/crates/core/src/time.rs index 2acfe81b..ec44a2d6 100644 --- a/crates/core/src/time.rs +++ b/crates/core/src/time.rs @@ -35,7 +35,6 @@ pub enum TimeAgo { } /// Seconds since the Unix epoch for an RFC 3339 UTC timestamp such as `2026-10-08T14:52:50Z`. -#[must_use] pub fn parse_rfc3339(text: &str) -> Option { let bytes = text.trim().as_bytes(); if bytes.len() < 19 || bytes.get(4) != Some(&b'-') || bytes.get(7) != Some(&b'-') || !matches!(bytes.get(10), Some(b'T' | b't' | b' ')) { @@ -84,7 +83,6 @@ fn days_from_civil(y: i64, m: i64, d: i64) -> Option { /// = `146_097` days) and the real year restored afterwards. jiff still does the month/day; the cycle /// count only shifts the year, keeping every `i64` exact (e.g. `i64::MAX` → year 292277026596, /// `i64::MIN` → year -292277022657), with no epoch fallback for a value the old code converted. -#[must_use] pub fn civil_from_unix(secs: i64) -> (i64, u32, u32) { let epoch = jiff::civil::Date::constant(1970, 1, 1); let days = secs.div_euclid(86_400); @@ -103,13 +101,11 @@ const MONTHS: [&str; 12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Au /// English three-letter month abbreviation for month `m` (1–12); `"?"` when out of range. /// Source key for `tr_ctx("month", …)` at the call site; never shown untranslated in /// non-English UI. -#[must_use] pub fn month_short_en(m: u32) -> &'static str { if (1..=12).contains(&m) { MONTHS.get((m - 1) as usize).copied().unwrap_or("?") } else { "?" } } /// `Oct 8, 2026` -#[must_use] pub fn format_date(secs: i64) -> String { let (y, m, d) = civil_from_unix(secs); let month = month_short_en(m); @@ -119,7 +115,6 @@ pub fn format_date(secs: i64) -> String { /// Classify a timestamp for translation-neutral rendering (no allocation, no English). /// Thresholds match [`format_ago`]: <60s → [`TimeAgo::JustNow`], <1h → minutes, /// <1d → hours, <2d → yesterday, <30d → days, older → [`TimeAgo::Date`]. -#[must_use] pub fn ago_kind(secs: i64, now: i64) -> TimeAgo { let dt = now.saturating_sub(secs); if dt < 60 { @@ -140,7 +135,6 @@ pub fn ago_kind(secs: i64, now: i64) -> TimeAgo { /// `just now`, `5 min ago`, `3 h ago`, `yesterday`, `4 days ago`, or the date. /// /// English-only fallback; translatable UI should match on [`ago_kind`] instead. -#[must_use] pub fn format_ago(secs: i64, now: i64) -> String { match ago_kind(secs, now) { TimeAgo::JustNow => "just now".into(), diff --git a/crates/core/src/version.rs b/crates/core/src/version.rs index cb649a1d..e0409170 100644 --- a/crates/core/src/version.rs +++ b/crates/core/src/version.rs @@ -8,7 +8,6 @@ pub use semver::Version; /// /// Accepts `v0.5.0`, `0.5.0`, `0.2.0-rc.1`, Debian's `0.2.0~rc.1-1`, and the two-part `0.5` /// some platforms report. Build metadata is kept but never affects ordering. -#[must_use] pub fn parse(text: &str) -> Option { let t = text.trim(); let t = t.strip_prefix(['v', 'V']).unwrap_or(t); @@ -36,7 +35,6 @@ pub fn parse(text: &str) -> Option { /// Reads a version as a system package manager reports it, dropping what the packaging adds: /// an epoch (`1:`), the package revision (`-1`, `-2.fc40`), Debian's `~` pre-release spelling, and /// a VCS snapshot suffix (`0.3.0.r47.g47f9306` from an AUR `-git` package, read as `0.3.0`). -#[must_use] pub fn parse_package(text: &str) -> Option { let t = text.trim(); // Epoch. @@ -100,19 +98,16 @@ fn digits(text: &str, from: usize) -> Option<(u64, usize)> { } /// A version that's a plain `X.Y.Z` with no pre-release suffix. -#[must_use] pub fn is_stable(v: &Version) -> bool { v.pre.is_empty() } /// Orders by precedence, ignoring build metadata. -#[must_use] pub fn compare(a: &Version, b: &Version) -> Ordering { a.cmp_precedence(b) } /// True when `latest` is newer than `installed`. -#[must_use] pub fn is_newer(latest: &Version, installed: &Version) -> bool { compare(latest, installed) == Ordering::Greater } @@ -120,7 +115,6 @@ pub fn is_newer(latest: &Version, installed: &Version) -> bool { /// Platforms that only record `X.Y.Z` (the MSI `ProductVersion`, `CFBundleShortVersionString`) /// drop a pre-release suffix. A numeric-only installed version therefore counts as current when it /// matches a pre-release's numbers, rather than nagging forever. -#[must_use] pub fn is_update(latest: &Version, installed: &Version) -> bool { if installed.pre.is_empty() && !latest.pre.is_empty()