Skip to main content

docutils_core/
settings.rs

1//! Runtime settings: mirrors the `docutils.core.Publisher` settings subset
2//! the port honors (`report_level`, `halt_level`, writer selection).
3
4/// Halt execution when a message at or above this level is produced.
5/// docutils levels: 1 info, 2 warning, 3 error, 4 severe, 5 none.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct Settings {
8    pub report_level: u8,
9    pub halt_level: u8,
10    pub writer_name: WriterName,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum WriterName {
15    Html5,
16    PseudoXml,
17    Null,
18}
19
20impl Default for Settings {
21    fn default() -> Self {
22        Self {
23            report_level: 2,
24            halt_level: 4,
25            writer_name: WriterName::Html5,
26        }
27    }
28}
29
30impl Settings {
31    pub fn halt_on(&self, level: u8) -> bool {
32        level >= self.halt_level
33    }
34}
35
36/// Error raised when `halt_level` trips.
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct Halt {
39    pub level: u8,
40    pub message: String,
41}
42
43impl std::fmt::Display for Halt {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        write!(f, "halted at level {}: {}", self.level, self.message)
46    }
47}
48
49impl std::error::Error for Halt {}