Debian Codegraph @

src/platform/tier.rs

raw symbols SCIP
1 //! Rust platform tiers
2
3 use crate::error::Error;
4 use core::{convert::TryFrom, fmt, str::FromStr};
5
6 #[cfg(feature = "serde")]
7 use serde::{de, ser, Deserialize, Serialize};
8
9 /// Rust platform tiers: support levels are organized into three tiers, each
10 /// with a different set of guarantees.
11 #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
12 pub enum Tier {
13 /// Tier 1 platforms can be thought of as “guaranteed to work”.
14 /// Specifically they will each satisfy the following requirements:
15 ///
16 /// * Official binary releases are provided for the platform.
17 /// * Automated testing is set up to run tests for the platform.
18 /// * Landing changes to the rust-lang/rust repository’s master branch
19 /// is gated on tests passing.
20 /// * Documentation for how to use and how to build the platform is available.
21 One,
22
23 /// Tier 2 platforms can be thought of as “guaranteed to build”. Automated
24 /// tests are not run so it’s not guaranteed to produce a working build,
25 /// but platforms often work to quite a good degree and patches are always
26 /// welcome!
27 ///
28 /// Specifically, these platforms are required to have each of the following:
29 ///
30 /// * Official binary releases are provided for the platform.
31 /// * Automated building is set up, but may not be running tests.
32 /// * Landing changes to the rust-lang/rust repository’s master branch is
33 /// gated on platforms building. For some platforms only the standard
34 /// library is compiled, but for others rustc and cargo are too.
35 Two,
36
37 /// Tier 3 platforms are those which the Rust codebase has support for, but
38 /// which are not built or tested automatically, and may not work.
39 /// Official builds are not available.
40 Three,
41 }
42
43 impl Tier {
44 /// Get a number identifying this tier
45 pub fn to_usize(self) -> usize {
46 match self {
47 Tier::One => 1,
48 Tier::Two => 2,
49 Tier::Three => 3,
50 }
51 }
52
53 /// Get a string identifying this tier
54 pub fn as_str(self) -> &'static str {
55 match self {
56 Tier::One => "tier1",
57 Tier::Two => "tier2",
58 Tier::Three => "tier3",
59 }
60 }
61 }
62
63 impl From<Tier> for usize {
64 fn from(tier: Tier) -> usize {
65 tier.to_usize()
66 }
67 }
68
69 impl TryFrom<usize> for Tier {
70 type Error = Error;
71
72 fn try_from(num: usize) -> Result<Tier, Error> {
73 match num {
74 1 => Ok(Tier::One),
75 2 => Ok(Tier::Two),
76 3 => Ok(Tier::Three),
77 _ => Err(Error),
78 }
79 }
80 }
81
82 impl FromStr for Tier {
83 type Err = Error;
84
85 fn from_str(s: &str) -> Result<Tier, Error> {
86 match s {
87 "tier1" => Ok(Tier::One),
88 "tier2" => Ok(Tier::Two),
89 "tier3" => Ok(Tier::Three),
90 _ => Err(Error),
91 }
92 }
93 }
94
95 impl fmt::Display for Tier {
96 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97 f.write_str(self.as_str())
98 }
99 }
100
101 #[cfg(feature = "serde")]
102 impl Serialize for Tier {
103 fn serialize<S: ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
104 serializer.serialize_str(self.as_str())
105 }
106 }
107
108 #[cfg(all(feature = "serde", feature = "std"))]
109 impl<'de> Deserialize<'de> for Tier {
110 fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
111 use de::Error;
112 std::string::String::deserialize(deserializer)?
113 .parse()
114 .map_err(D::Error::custom)
115 }
116 }