Skip to main content

mlb_api/requests/meta/
pitch_codes.rs

1use serde::Deserialize;
2
3id!(#[doc = "A [`String`] representing a pitch, such as \"F\" for Foul, \"S\" for Swinging Strike, etc."] PitchCodeId { code: String });
4
5#[must_use]
6pub(crate) fn unknown_pitch_code() -> PitchCodeId {
7	PitchCodeId::new("N")
8}
9
10/// A detailed `struct` representing everything logic-related that happened with a pitch.
11///
12/// ## Examples
13/// ```
14/// PitchCode {
15///     id: "F".into(),
16///     description: "Strike - Foul".into(),
17///     has_swing: true,
18///     is_whiff: false,
19///     made_contact_fair: false,
20///     is_strike: true,
21///     is_ball: false,
22///     is_pitch: true,
23///     pitch_result_text: "Foul Ball".into(),
24///     is_bunt_attempt: false,
25///     made_contact: true
26/// }
27/// ```
28#[allow(clippy::struct_excessive_bools, reason = "false positive")]
29#[derive(Debug, Deserialize, Clone)]
30#[serde(rename_all = "camelCase")]
31pub struct PitchCode {
32	pub description: String,
33	#[serde(rename = "swingStatus")]
34	pub has_swing: bool,
35	#[serde(rename = "swingMissStatus")]
36	pub is_whiff: bool,
37	#[serde(rename = "swingContactStatus")]
38	pub made_contact_fair: bool,
39	#[serde(rename = "strikeStatus")]
40	pub is_strike: bool,
41	#[serde(rename = "ballStatus")]
42	pub is_ball: bool,
43	#[serde(rename = "pitchStatus")]
44	pub is_pitch: bool,
45	pub pitch_result_text: String,
46	#[serde(rename = "buntAttemptStatus")]
47	pub is_bunt_attempt: bool,
48	#[serde(rename = "contactStatus")]
49	pub made_contact: bool,
50	#[serde(flatten)]
51	pub id: PitchCodeId,
52}
53
54id_only_eq_impl!(PitchCode, id);
55meta_kind_impl!("pitchCodes" => PitchCode);
56tiered_request_entry_cache_impl!(PitchCode.id: PitchCodeId);
57test_impl!(PitchCode);