off_rs/parser/options.rs
1use super::color_format::ColorFormat;
2
3/// Defines the options for the [`Parser`](`crate::parser::Parser`).
4#[derive(Debug, Copy, Clone, PartialEq, Default)]
5pub struct Options {
6 /// The color format that is parsed from the `off` string.
7 pub color_format: ColorFormat,
8 /// The limits that are checked while parsing the `off` string.
9 pub limits: Limits,
10}
11
12/// Defines limits for the [`Parser`](`crate::parser::Parser`).
13///
14/// # Note
15///
16/// When these limits are exceeded during the [`parse`](`crate::parser::Parser::<'_>::parse`)
17/// processes an error will be returned.
18///
19/// Use the [`Default`](`Limits::default`) implementation for reasonable values.
20///
21/// # Examples
22///
23/// ```rust
24/// use off_rs::parser::options::Limits;
25/// let limits = Limits::default();
26/// ```
27#[derive(Debug, Copy, Clone, PartialEq, Eq)]
28pub struct Limits {
29 /// Defines the maximum amount of vertices the parser accepts.
30 pub vertex_count: usize,
31
32 /// Defines the maximum amount of faces the parser accepts.
33 pub face_count: usize,
34
35 /// Defines the maximum amount of vertices per face the parser accepts.
36 pub face_vertex_count: usize,
37}
38
39impl Default for Limits {
40 /// Creates a new [`Limits`] with reasonable values.
41 fn default() -> Self {
42 Self {
43 vertex_count: 10000,
44 face_count: 1000,
45 face_vertex_count: 64,
46 }
47 }
48}
49
50impl Limits {
51 /// Limits instance with all values set to their respective maximum value.
52 pub const MAX: Self = Self {
53 vertex_count: usize::MAX,
54 face_count: usize::MAX,
55 face_vertex_count: usize::MAX,
56 };
57
58 /// Limits instance with all values set to their respective minimum value.
59 pub const MIN: Self = Self {
60 vertex_count: usize::MIN,
61 face_count: usize::MIN,
62 face_vertex_count: usize::MIN,
63 };
64}