cargo-semver-checks 0.7.0

Scan your Rust crate for semver violations.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::{fs::File, io::Read};

use anyhow::Context;
use rustdoc_types::Crate;

pub(crate) fn load_rustdoc_from_file(path: &str) -> anyhow::Result<Crate> {
    // Parsing JSON after fully reading a file into memory is much faster than
    // parsing directly from a file, even if buffered:
    // https://github.com/serde-rs/json/issues/160
    let mut s = String::new();
    File::open(path)
        .with_context(|| format!("Failed to open rustdoc JSON output file {:?}", path))?
        .read_to_string(&mut s)
        .with_context(|| format!("Failed to read rustdoc JSON output file {:?}", path))?;

    serde_json::from_str(&s)
        .with_context(|| format!("Failed to parse rustdoc JSON output file {:?}", path))
}