rust_mir2_core 0.1.1

Shared Rust MIR extraction model and helpers for rust_mir2
Documentation
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

pub const WRAPPER_MODE_ENV: &str = "RUST_MIR2_MODE";
pub const OUTPUT_DIR_ENV: &str = "RUST_MIR2_OUTPUT_DIR";
pub const EXPECTED_PACKAGES_ENV: &str = "RUST_MIR2_EXPECTED_PACKAGES";

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InvocationMode {
    Library,
    WorkspaceWrapper,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InputKind {
    SingleCrate,
    Workspace,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TargetProject {
    pub input_kind: InputKind,
    pub project_root: PathBuf,
    pub manifest_path: PathBuf,
    pub expected_package_names: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TargetMirDump {
    pub package_name: String,
    pub crate_name: String,
    pub target_name: String,
    pub target_kind: String,
    pub target_profile: String,
    pub target_src_path: PathBuf,
    pub target_identity: String,
    pub mir_raw: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PackageMirDump {
    pub package_name: String,
    pub targets: Vec<TargetMirDump>,
    pub merged_mir_raw: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WorkspaceMirDump {
    pub project_path: PathBuf,
    pub packages: Vec<PackageMirDump>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RustMir2Error {
    pub message: String,
}

impl std::fmt::Display for RustMir2Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.message)
    }
}

impl std::error::Error for RustMir2Error {}

impl From<anyhow::Error> for RustMir2Error {
    fn from(value: anyhow::Error) -> Self {
        Self {
            message: format!("{value:#}"),
        }
    }
}

impl From<serde_json::Error> for RustMir2Error {
    fn from(value: serde_json::Error) -> Self {
        Self {
            message: format!("{value:#}"),
        }
    }
}

impl From<std::io::Error> for RustMir2Error {
    fn from(value: std::io::Error) -> Self {
        Self {
            message: format!("{value:#}"),
        }
    }
}