caniuse_serde/
Category.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/// One or more categories are associated with each Feature
6#[allow(missing_docs)]
7#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
8pub enum Category
9{
10	HTML5,
11	CSS,
12	CSS2,
13	CSS3,
14	SVG,
15	PNG,
16	JS_API,
17	Canvas,
18	DOM,
19	Other,
20	JS,
21	Security,
22	
23	#[doc(hidden)] __Nonexhaustive,
24	
25	/// A category that did not exist in the caniuse.com data when this library was created
26	Unknown(String),
27}
28
29impl Default for Category
30{
31	/// Defaults to Category::Other
32	#[inline(always)]
33	fn default() -> Self
34	{
35		Category::Other
36	}
37}
38
39impl<'de> Deserialize<'de> for Category
40{
41	/// Deserialize using Serde
42	#[inline(always)]
43	fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
44	{
45		struct CategoryVisitor;
46		
47		impl<'de> Visitor<'de> for CategoryVisitor
48		{
49			type Value = Category;
50			
51			#[inline(always)]
52			fn expecting(&self, formatter: &mut Formatter) -> fmt::Result
53			{
54				formatter.write_str("an era name starting with 'e' followed by a signed integer")
55			}
56			
57			#[inline(always)]
58			fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E>
59			{
60				use self::Category::*;
61				
62				let result = match v
63				{
64					"HTML5" => HTML5,
65					"CSS" => CSS,
66					"CSS2" => CSS2,
67					"CSS3" => CSS3,
68					"SVG" => SVG,
69					"PNG" => PNG,
70					"JS API" => JS_API,
71					"Canvas" => Canvas,
72					"DOM" => DOM,
73					"Other" => Other,
74					"JS" => JS,
75					"Security" => Security,
76					
77					_ => Unknown(v.to_owned()),
78				};
79				Ok(result)
80			}
81			
82			#[inline(always)]
83			fn visit_string<E: de::Error>(self, v: String) -> Result<Self::Value, E>
84			{
85				use self::Category::*;
86				
87				let result = match &v[..]
88				{
89					"HTML5" => HTML5,
90					"CSS" => CSS,
91					"CSS2" => CSS2,
92					"CSS3" => CSS3,
93					"SVG" => SVG,
94					"PNG" => PNG,
95					"JS API" => JS_API,
96					"Canvas" => Canvas,
97					"DOM" => DOM,
98					"Other" => Other,
99					"JS" => JS,
100					"Security" => Security,
101					
102					_ => Unknown(v),
103				};
104				Ok(result)
105			}
106		}
107		
108		deserializer.deserialize_str(CategoryVisitor)
109	}
110}