wdl_format/config/
max_line_length.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum MaxLineLengthError {
8 #[error(
10 "`{0}` is outside the allowed range for the max line length: `{min}-{max}`",
11 min = MIN_MAX_LINE_LENGTH,
12 max = MAX_MAX_LINE_LENGTH
13 )]
14 OutsideAllowedRange(usize),
15}
16
17pub const DEFAULT_MAX_LINE_LENGTH: usize = 90;
19pub const MIN_MAX_LINE_LENGTH: usize = 60;
21pub const MAX_MAX_LINE_LENGTH: usize = 240;
23
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26pub struct MaxLineLength(Option<usize>);
27
28impl MaxLineLength {
29 pub fn try_new(value: usize) -> Result<Self, MaxLineLengthError> {
33 let val = match value {
34 0 => Self(None),
35 MIN_MAX_LINE_LENGTH..=MAX_MAX_LINE_LENGTH => Self(Some(value)),
36 _ => {
37 return Err(MaxLineLengthError::OutsideAllowedRange(value));
38 }
39 };
40 Ok(val)
41 }
42
43 pub fn get(&self) -> Option<usize> {
45 self.0
46 }
47}
48
49impl Default for MaxLineLength {
50 fn default() -> Self {
51 Self(Some(DEFAULT_MAX_LINE_LENGTH))
52 }
53}