caniuse_serde/
Status.rs

1// This file is part of caniuse-serde. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of caniuse-serde. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT.
3
4
5/// A Status reflects the 'standardisation' of a feature
6#[allow(missing_docs)]
7#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
8pub enum Status
9{
10	W3CRecommendation,
11	W3CProposedRecommendation,
12	W3CCandidateRecommendation,
13	W3CWorkingDraft,
14	WhatwgLivingStandard,
15	Other,
16	UnofficialOrNote,
17	
18	#[doc(hidden)] __Nonexhaustive,
19	
20	/// A status that did not exist in the caniuse.com data when this library was created
21	Unknown(String),
22}
23
24impl Default for Status
25{
26	/// Defaults to Status::Other
27	#[inline(always)]
28	fn default() -> Self
29	{
30		Status::Other
31	}
32}
33
34impl<'de> Deserialize<'de> for Status
35{
36	/// Deserialize using Serde
37	fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
38	{
39		struct StatusVisitor;
40		
41		impl<'de> Visitor<'de> for StatusVisitor
42		{
43			type Value = Status;
44			
45			fn expecting(&self, formatter: &mut Formatter) -> fmt::Result
46			{
47				formatter.write_str("an era name starting with 'e' followed by a signed integer")
48			}
49			
50			fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E>
51			{
52				use self::Status::*;
53				
54				let result = match v
55				{
56					"rec" => W3CRecommendation,
57					"pr" => W3CProposedRecommendation,
58					"cr" => W3CCandidateRecommendation,
59					"wd" => W3CWorkingDraft,
60					"ls" => WhatwgLivingStandard,
61					"other" => Other,
62					"unoff" => UnofficialOrNote,
63					
64					_ => Unknown(v.to_owned()),
65				};
66				Ok(result)
67			}
68			
69			fn visit_string<E: de::Error>(self, v: String) -> Result<Self::Value, E>
70			{
71				use self::Status::*;
72				
73				let result = match &v[..]
74				{
75					"rec" => W3CRecommendation,
76					"pr" => W3CProposedRecommendation,
77					"cr" => W3CCandidateRecommendation,
78					"wd" => W3CWorkingDraft,
79					"ls" => WhatwgLivingStandard,
80					"other" => Other,
81					"unoff" => UnofficialOrNote,
82					
83					_ => Unknown(v),
84				};
85				Ok(result)
86			}
87		}
88		
89		deserializer.deserialize_str(StatusVisitor)
90	}
91}
92
93impl Status
94{
95	/// A short piece of text describing this status.
96	/// Only optional if the discriminant is Status::Unknown or the caniuse.com database is broken in some way.
97	#[inline(always)]
98	pub fn description<'a>(&self, canIUse: &'a CanIUse) -> Option<&'a str>
99	{
100		canIUse.status_description(self)
101	}
102}