Skip to main content

publish_string_with

Function publish_string_with 

Source
pub fn publish_string_with(
    source: &str,
    settings: &Settings,
    base_dir: Option<PathBuf>,
) -> Result<(String, Document), Halt>
Expand description

Publish source to a string with the configured writer.

Mirrors publish_string (real writer): loose messages gather into a closing section and sub-threshold messages are filtered.

Examples found in repository?
examples/bench.rs (line 23)
10fn main() {
11    let path = std::env::args().nth(1).expect("usage: bench <file.rst> <iters>");
12    let iters: usize = std::env::args()
13        .nth(2)
14        .expect("usage: bench <file.rst> <iters>")
15        .parse()
16        .expect("iters must be a number");
17    let source = std::fs::read_to_string(&path).expect("read input");
18    let settings = Settings {
19        report_level: 1,
20        ..Settings::default()
21    };
22    // Warm-up (allocator, first-parse caches) outside the clock.
23    let (first, _) = publish_string_with(&source, &settings, None).expect("bench parse");
24    let start = std::time::Instant::now();
25    let mut len = 0;
26    for _ in 0..iters {
27        let (html, _) = publish_string_with(&source, &settings, None).expect("bench parse");
28        len = html.len();
29    }
30    let ms = start.elapsed().as_secs_f64() * 1000.0;
31    println!("iters={iters} elapsed_ms={ms:.1} html_len={len} first_len={}", first.len());
32}
More examples
Hide additional examples
examples/publish.rs (line 41)
10fn main() {
11    let path = std::env::args().nth(1).expect("usage: publish <file.rst>");
12    let source = std::fs::read_to_string(&path).expect("read input");
13    // Parity harness: report everything (mirrors the oracle at
14    // report_level 1); default filtering is covered by unit tests.
15    let settings = Settings {
16        report_level: 1,
17        ..Settings::default()
18    };
19    let doc = match publish_doctree_with(&source, &settings, None) {
20        Ok(doc) => doc,
21        Err(h) => {
22            eprintln!("HALT {h}");
23            std::process::exit(1);
24        }
25    };
26    eprintln!("-- messages:");
27    for m in &doc.messages {
28        let line = m
29            .line
30            .map(|n| n.to_string())
31            .unwrap_or_else(|| "None".into());
32        eprintln!(
33            "MSG level={} line={} {}",
34            m.level,
35            line,
36            m.text.replace('\n', "\\n")
37        );
38    }
39    eprintln!("-- astext --");
40    eprintln!("{}", doc.astext());
41    match publish_string_with(&source, &settings, None) {
42        Ok((html, _)) => println!("{html}"),
43        Err(h) => {
44            eprintln!("HALT {h}");
45            std::process::exit(1);
46        }
47    }
48}