Skip to main content

newsapi_rust/
version.rs

1//! API Version abstraction.
2
3/// API version enum for NewsAPI. Currently only supports v2, but designed for future extensibility.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum ApiVersion {
6    /// Version 2 of the NewsAPI.
7    #[default]
8    V2,
9}
10
11impl ApiVersion {
12    /// Get the API path segment for this version. (e.g. `"/v2"`).
13    pub fn path(&self) -> &'static str {
14        match self {
15            ApiVersion::V2 => "/v2",
16        }
17    }
18}
19
20impl std::fmt::Display for ApiVersion {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            ApiVersion::V2 => write!(f, "v2"),
24        }
25    }
26}