Skip to main content

chrome_for_testing/api/
mod.rs

1use crate::api::version::Version;
2use platform::Platform;
3use reqwest::Url;
4use serde::{Deserialize, Serialize};
5use std::sync::LazyLock;
6
7/// Chrome release channel definitions.
8pub mod channel;
9
10/// Platform identification for different operating systems and architectures.
11pub mod platform;
12
13/// Version parsing and representation.
14pub mod version;
15
16/// API request for a list of working releases. None are assigned to any channel.
17pub mod known_good_versions;
18
19/// The last working releases for each channel.
20pub mod last_known_good_versions;
21
22/// The standard chrome-for-testing API endpoint protocol and hostname.
23///
24/// Consult <https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints>
25/// for verification.
26pub static API_BASE_URL: LazyLock<Url> =
27    LazyLock::new(|| Url::parse("https://googlechromelabs.github.io").expect("Valid URL"));
28
29/// Represents a download link for a specific platform.
30#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
31pub struct Download {
32    /// The target platform for this download.
33    pub platform: Platform,
34
35    /// The download URL.
36    pub url: String,
37}
38
39/// Extension trait for download slices, providing platform-based lookup.
40pub trait DownloadsByPlatform {
41    /// Returns the download entry for the given platform, if available.
42    fn for_platform(&self, platform: Platform) -> Option<&Download>;
43}
44
45impl DownloadsByPlatform for [Download] {
46    fn for_platform(&self, platform: Platform) -> Option<&Download> {
47        self.iter().find(|d| d.platform == platform)
48    }
49}
50
51/// Trait for types that contain a version identifier.
52pub trait HasVersion {
53    /// Returns the version identifier.
54    fn version(&self) -> Version;
55}
56
57impl HasVersion for known_good_versions::VersionWithoutChannel {
58    fn version(&self) -> Version {
59        self.version
60    }
61}
62
63impl HasVersion for last_known_good_versions::VersionInChannel {
64    fn version(&self) -> Version {
65        self.version
66    }
67}