rustpython_parser_core/
format.rs

1/// Transforms a value prior to formatting it.
2#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, is_macro::Is)]
3#[repr(i8)]
4pub enum ConversionFlag {
5    /// No conversion
6    None = -1, // CPython uses -1
7    /// Converts by calling `str(<value>)`.
8    Str = b's' as i8,
9    /// Converts by calling `ascii(<value>)`.
10    Ascii = b'a' as i8,
11    /// Converts by calling `repr(<value>)`.
12    Repr = b'r' as i8,
13}
14
15impl ConversionFlag {
16    pub fn to_byte(&self) -> Option<u8> {
17        match self {
18            Self::None => None,
19            flag => Some(*flag as u8),
20        }
21    }
22    pub fn to_char(&self) -> Option<char> {
23        Some(self.to_byte()? as char)
24    }
25}