/// The record separator used between fixed-width records.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub enum RecordSeparator {
    /// No separator between records; records are purely positional.
    #[default]
    None,
    /// Line feed (`\n`), typical on Linux/macOS.
    Lf,
    /// Carriage return (`\r`), used on classic Mac systems.
    Cr,
    /// Carriage return + line feed (`\r\n`), typical on Windows.
    CrLf,
    /// A custom separator byte sequence.
    Custom(Vec<u8>),
}

impl RecordSeparator {
    /// Returns the byte length of this separator.
    #[must_use]
    #[inline]
    pub fn len(&self) -> usize {
        match self {
            Self::None => 0,
            Self::Lf | Self::Cr => 1,
            Self::CrLf => 2,
            Self::Custom(bytes) => bytes.len(),
        }
    }

    /// Returns `true` if this separator has zero length.
    #[must_use]
    #[inline]
    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    /// Returns the expected separator bytes, or an empty slice for [`None`](Self::None).
    #[must_use]
    pub fn as_bytes(&self) -> &[u8] {
        match self {
            Self::None => &[],
            Self::Lf => b"\n",
            Self::Cr => b"\r",
            Self::CrLf => b"\r\n",
            Self::Custom(bytes) => bytes,
        }
    }
}
