Skip to main content

mlb_api/requests/meta/
hit_trajectories.rs

1use derive_more::Display;
2use serde::Deserialize;
3
4#[derive(Debug, Deserialize, PartialEq, Eq, Copy, Clone, Display, Hash)]
5#[serde(try_from = "__HitTrajectoryStruct")]
6pub enum HitTrajectory {
7	#[display("Bunt - Ground Ball")]
8	BuntGrounder,
9
10	#[display("Bunt - Popup")]
11	BuntPopup,
12
13	#[display("Bunt - Line Drive")]
14	BuntLineDrive,
15
16	#[display("Line Drive")]
17	LineDrive,
18
19	#[display("Ground Ball")]
20	GroundBall,
21
22	#[display("Fly Ball")]
23	FlyBall,
24
25	#[display("Popup")]
26	Popup,
27}
28
29#[derive(Deserialize)]
30#[doc(hidden)]
31struct __HitTrajectoryStruct {
32	code: String,
33}
34
35impl TryFrom<__HitTrajectoryStruct> for HitTrajectory {
36	type Error = &'static str;
37
38	fn try_from(value: __HitTrajectoryStruct) -> Result<Self, Self::Error> {
39		Ok(match &*value.code {
40			"bunt_grounder" => Self::BuntGrounder,
41			"bunt_popup" => Self::BuntPopup,
42			"bunt_line_drive" => Self::BuntLineDrive,
43			"line_drive" => Self::LineDrive,
44			"ground_ball" => Self::GroundBall,
45			"fly_ball" => Self::FlyBall,
46			"popup" => Self::Popup,
47			_ => return Err("unknown hit trajectory"),
48		})
49	}
50}
51
52meta_kind_impl!("hitTrajectories" => HitTrajectory);
53static_request_entry_cache_impl!(HitTrajectory);
54test_impl!(HitTrajectory);