1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
// 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.
// 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.


/// A Status reflects the 'standardisation' of a feature
#[allow(missing_docs)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum Status
{
	W3CRecommendation,
	W3CProposedRecommendation,
	W3CCandidateRecommendation,
	W3CWorkingDraft,
	WhatwgLivingStandard,
	Other,
	UnofficialOrNote,
	
	#[doc(hidden)] __Nonexhaustive,
	
	/// A status that did not exist in the caniuse.com data when this library was created
	Unknown(String),
}

impl Default for Status
{
	/// Defaults to Status::Other
	#[inline(always)]
	fn default() -> Self
	{
		Status::Other
	}
}

impl<'de> Deserialize<'de> for Status
{
	/// Deserialize using Serde
	fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
	{
		struct StatusVisitor;
		
		impl<'de> Visitor<'de> for StatusVisitor
		{
			type Value = Status;
			
			fn expecting(&self, formatter: &mut Formatter) -> fmt::Result
			{
				formatter.write_str("an era name starting with 'e' followed by a signed integer")
			}
			
			fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E>
			{
				use self::Status::*;
				
				let result = match v
				{
					"rec" => W3CRecommendation,
					"pr" => W3CProposedRecommendation,
					"cr" => W3CCandidateRecommendation,
					"wd" => W3CWorkingDraft,
					"ls" => WhatwgLivingStandard,
					"other" => Other,
					"unoff" => UnofficialOrNote,
					
					_ => Unknown(v.to_owned()),
				};
				Ok(result)
			}
			
			fn visit_string<E: de::Error>(self, v: String) -> Result<Self::Value, E>
			{
				use self::Status::*;
				
				let result = match &v[..]
				{
					"rec" => W3CRecommendation,
					"pr" => W3CProposedRecommendation,
					"cr" => W3CCandidateRecommendation,
					"wd" => W3CWorkingDraft,
					"ls" => WhatwgLivingStandard,
					"other" => Other,
					"unoff" => UnofficialOrNote,
					
					_ => Unknown(v),
				};
				Ok(result)
			}
		}
		
		deserializer.deserialize_str(StatusVisitor)
	}
}

impl Status
{
	/// A short piece of text describing this status.
	/// Only optional if the discriminant is Status::Unknown or the caniuse.com database is broken in some way.
	#[inline(always)]
	pub fn description<'a>(&self, canIUse: &'a CanIUse) -> Option<&'a str>
	{
		canIUse.status_description(self)
	}
}