qubit_fs/metadata/resource_version.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Opaque provider resource versions.
9
10use std::fmt::Display;
11use std::fmt::Formatter;
12use std::fmt::Result as FmtResult;
13
14/// Opaque version, generation, or ETag reported by a provider.
15///
16/// # Examples
17///
18/// ```rust
19/// use qubit_fs::metadata::ResourceVersion;
20///
21/// let version = ResourceVersion::new("v1");
22/// assert_eq!("v1", version.as_str());
23/// ```
24#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct ResourceVersion(
26 /// Provider-defined opaque version text.
27 String,
28);
29
30impl ResourceVersion {
31 /// Creates an opaque resource version.
32 ///
33 /// # Parameters
34 /// - `value`: Provider-defined version text.
35 ///
36 /// # Returns
37 /// A resource version preserving `value` exactly.
38 #[inline]
39 #[must_use]
40 pub fn new(value: impl Into<String>) -> Self {
41 Self(value.into())
42 }
43
44 /// Returns the provider-defined version text.
45 ///
46 /// # Returns
47 /// The borrowed version text.
48 #[inline]
49 #[must_use]
50 pub fn as_str(&self) -> &str {
51 &self.0
52 }
53}
54
55impl Display for ResourceVersion {
56 #[inline]
57 fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
58 formatter.write_str(self.as_str())
59 }
60}
61
62impl AsRef<str> for ResourceVersion {
63 #[inline]
64 fn as_ref(&self) -> &str {
65 self.as_str()
66 }
67}
68
69impl From<&str> for ResourceVersion {
70 #[inline]
71 fn from(value: &str) -> Self {
72 Self::new(value)
73 }
74}
75
76impl From<String> for ResourceVersion {
77 #[inline]
78 fn from(value: String) -> Self {
79 Self::new(value)
80 }
81}