Skip to main content

custom_motorcycle_helmet_styles/
lib.rs

1#![forbid(unsafe_code)]
2//! Motorcycle helmet shell silhouettes, paintable zones and surface finishes across 33 styles and 5 rider categories.
3//!
4//! Maintained from the open shell catalog powering [Custom Motorcycle Helmet](https://custommotorcyclehelmet.com)
5//! and its interactive [3D motorcycle helmet designer](https://custommotorcyclehelmet.com/design?utm_source=docsrs&utm_medium=referral&utm_campaign=crates).
6//!
7//! ## Example
8//!
9//! ```rust
10//! use custom_motorcycle_helmet_styles::{by_category, find_style, paintable_zones, STYLES};
11//!
12//! let shell = find_style("Retro full face").unwrap();
13//! assert_eq!(shell.id, "retro-full-face");
14//! assert_eq!(by_category("Motocross").len(), 7);
15//! assert_eq!(paintable_zones("jet-long-shield"), &["crown", "forehead", "sides", "back", "neck"]);
16//! assert_eq!(STYLES.len(), 33);
17//! ```
18
19/// Dataset revision date (ISO 8601).
20pub const UPDATED: &str = "2026-11-16";
21
22/// Raw JSON dataset identical to `data/styles.json`.
23pub const RAW_JSON: &str = include_str!("../data/styles.json");
24
25/// Supported clearcoat and material finishes for 3D helmet previews.
26pub static FINISHES: &[&str] = &["gloss", "matte", "chrome", "pearl", "carbon-fiber"];
27
28/// Full paintable shell zone list when a closed chin bar is present.
29pub static ZONES: &[&str] = &["crown", "forehead", "chin", "sides", "back", "neck"];
30
31/// Paintable shell zone list for open-face and half helmets without a chin bar.
32pub static OPEN_ZONES: &[&str] = &["crown", "forehead", "sides", "back", "neck"];
33
34/// Metadata for a single motorcycle helmet shell silhouette.
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub struct HelmetStyle {
37    pub id: &'static str,
38    pub category: &'static str,
39    pub model: &'static str,
40    pub has_peak: bool,
41    pub has_chin_bar: bool,
42}
43
44/// All 33 motorcycle helmet shell silhouettes across 5 rider categories.
45pub static STYLES: &[HelmetStyle] = &[
46    HelmetStyle {
47        id: "retro-full-face",
48        category: "Full face",
49        model: "Retro full face",
50        has_peak: true,
51        has_chin_bar: true,
52    },
53    HelmetStyle {
54        id: "modern-full-face",
55        category: "Full face",
56        model: "Modern full face",
57        has_peak: false,
58        has_chin_bar: true,
59    },
60    HelmetStyle {
61        id: "street-full-face",
62        category: "Full face",
63        model: "Street full face",
64        has_peak: false,
65        has_chin_bar: true,
66    },
67    HelmetStyle {
68        id: "race-tail-wing",
69        category: "Full face",
70        model: "Race with tail wing",
71        has_peak: false,
72        has_chin_bar: true,
73    },
74    HelmetStyle {
75        id: "sport-tail-wing",
76        category: "Full face",
77        model: "Sport with tail wing",
78        has_peak: false,
79        has_chin_bar: true,
80    },
81    HelmetStyle {
82        id: "vintage-full-face",
83        category: "Full face",
84        model: "Vintage full face",
85        has_peak: false,
86        has_chin_bar: true,
87    },
88    HelmetStyle {
89        id: "retro-goggles",
90        category: "Full face",
91        model: "Retro with goggles",
92        has_peak: false,
93        has_chin_bar: true,
94    },
95    HelmetStyle {
96        id: "rally-full-face",
97        category: "Full face",
98        model: "Rally full face",
99        has_peak: true,
100        has_chin_bar: true,
101    },
102    HelmetStyle {
103        id: "slim-full-face",
104        category: "Full face",
105        model: "Slim full face",
106        has_peak: false,
107        has_chin_bar: true,
108    },
109    HelmetStyle {
110        id: "car-racing-style",
111        category: "Full face",
112        model: "Car racing style",
113        has_peak: false,
114        has_chin_bar: true,
115    },
116    HelmetStyle {
117        id: "race-chin-spoiler",
118        category: "Full face",
119        model: "Race with chin spoiler",
120        has_peak: false,
121        has_chin_bar: true,
122    },
123    HelmetStyle {
124        id: "rounded-full-face",
125        category: "Full face",
126        model: "Rounded full face",
127        has_peak: false,
128        has_chin_bar: true,
129    },
130    HelmetStyle {
131        id: "adventure-dual-sport",
132        category: "Adventure",
133        model: "Adventure dual sport",
134        has_peak: true,
135        has_chin_bar: true,
136    },
137    HelmetStyle {
138        id: "street-dual-sport",
139        category: "Adventure",
140        model: "Street dual sport",
141        has_peak: true,
142        has_chin_bar: true,
143    },
144    HelmetStyle {
145        id: "retro-motocross",
146        category: "Motocross",
147        model: "Retro motocross",
148        has_peak: true,
149        has_chin_bar: true,
150    },
151    HelmetStyle {
152        id: "retro-scrambler",
153        category: "Motocross",
154        model: "Retro scrambler, no peak",
155        has_peak: false,
156        has_chin_bar: true,
157    },
158    HelmetStyle {
159        id: "enduro-shell",
160        category: "Motocross",
161        model: "Enduro shell",
162        has_peak: true,
163        has_chin_bar: true,
164    },
165    HelmetStyle {
166        id: "downhill-full-face",
167        category: "Motocross",
168        model: "Downhill full face",
169        has_peak: true,
170        has_chin_bar: true,
171    },
172    HelmetStyle {
173        id: "sharp-motocross",
174        category: "Motocross",
175        model: "Sharp motocross",
176        has_peak: true,
177        has_chin_bar: true,
178    },
179    HelmetStyle {
180        id: "motocross",
181        category: "Motocross",
182        model: "Motocross",
183        has_peak: true,
184        has_chin_bar: true,
185    },
186    HelmetStyle {
187        id: "motocross-goggles",
188        category: "Motocross",
189        model: "Motocross with goggles",
190        has_peak: true,
191        has_chin_bar: true,
192    },
193    HelmetStyle {
194        id: "retro-open-face",
195        category: "Open face",
196        model: "Retro open face",
197        has_peak: false,
198        has_chin_bar: false,
199    },
200    HelmetStyle {
201        id: "jet-long-shield",
202        category: "Open face",
203        model: "Jet with long shield",
204        has_peak: false,
205        has_chin_bar: false,
206    },
207    HelmetStyle {
208        id: "retro-open-peak",
209        category: "Open face",
210        model: "Retro open with peak",
211        has_peak: true,
212        has_chin_bar: false,
213    },
214    HelmetStyle {
215        id: "open-face",
216        category: "Open face",
217        model: "Open face",
218        has_peak: false,
219        has_chin_bar: false,
220    },
221    HelmetStyle {
222        id: "classic-open-face",
223        category: "Open face",
224        model: "Classic open face",
225        has_peak: false,
226        has_chin_bar: false,
227    },
228    HelmetStyle {
229        id: "open-face-peak",
230        category: "Open face",
231        model: "Open face with peak",
232        has_peak: true,
233        has_chin_bar: false,
234    },
235    HelmetStyle {
236        id: "half-helmet",
237        category: "Half helmet",
238        model: "Half helmet",
239        has_peak: false,
240        has_chin_bar: false,
241    },
242    HelmetStyle {
243        id: "half-peak",
244        category: "Half helmet",
245        model: "Half with peak",
246        has_peak: true,
247        has_chin_bar: false,
248    },
249    HelmetStyle {
250        id: "shorty-half",
251        category: "Half helmet",
252        model: "Shorty half",
253        has_peak: false,
254        has_chin_bar: false,
255    },
256    HelmetStyle {
257        id: "beanie",
258        category: "Half helmet",
259        model: "Beanie",
260        has_peak: false,
261        has_chin_bar: false,
262    },
263    HelmetStyle {
264        id: "vintage-half",
265        category: "Half helmet",
266        model: "Vintage half",
267        has_peak: false,
268        has_chin_bar: false,
269    },
270    HelmetStyle {
271        id: "german-half",
272        category: "Half helmet",
273        model: "German half",
274        has_peak: false,
275        has_chin_bar: false,
276    }
277];
278
279fn norm(input: &str) -> String {
280    input
281        .chars()
282        .filter(|c| c.is_ascii_alphanumeric())
283        .map(|c| c.to_ascii_lowercase())
284        .collect()
285}
286
287/// Find a helmet shell style by `id` or `model` name (case and separator insensitive).
288pub fn find_style(query: &str) -> Option<&'static HelmetStyle> {
289    let q = norm(query);
290    if q.is_empty() {
291        return None;
292    }
293    for style in STYLES {
294        if norm(style.id) == q || norm(style.model) == q {
295            return Some(style);
296        }
297    }
298    for style in STYLES {
299        if norm(style.model).contains(&q) || norm(style.id).contains(&q) {
300            return Some(style);
301        }
302    }
303    None
304}
305
306/// Return all helmet styles in a rider category (e.g. `"Full face"`, `"Motocross"`, `"Half helmet"`).
307pub fn by_category(category: &str) -> Vec<&'static HelmetStyle> {
308    let c = norm(category);
309    STYLES.iter().filter(|s| norm(s.category) == c).collect()
310}
311
312/// Return the paintable shell zones available on the helmet style matched by `query`.
313pub fn paintable_zones(query: &str) -> &'static [&'static str] {
314    match find_style(query) {
315        Some(style) if style.has_chin_bar => ZONES,
316        Some(_) => OPEN_ZONES,
317        None => &[],
318    }
319}
320
321#[cfg(test)]
322mod tests {
323    use super::*;
324
325    #[test]
326    fn resolves_styles_and_paintable_zones() {
327        let s = find_style("retrofullface").expect("retro-full-face");
328        assert!(s.has_peak && s.has_chin_bar);
329        assert_eq!(paintable_zones("retro-full-face").len(), 6);
330        assert_eq!(paintable_zones("jet-long-shield").len(), 5);
331        assert_eq!(by_category("Full face").len(), 12);
332        assert!(RAW_JSON.contains("retro-full-face"));
333    }
334}