pdb-bindgen-codegen 0.1.0

Build-time discovery, PDB acquisition, and binding generation for pdb-bindgen.
Documentation
use std::error::Error as StdError;
use std::fmt;
use std::path::PathBuf;

#[derive(Debug)]
pub(crate) enum Error {
    Open {
        path: PathBuf,
        source: Box<dyn StdError + Send + Sync>,
    },
    Parse {
        operation: &'static str,
        detail: String,
    },
    InvalidUtf8 {
        operation: &'static str,
    },
    UnsupportedPrimitive {
        index: u32,
    },
    UnsupportedMachine {
        machine: u16,
    },
    InvalidReference {
        owner: u32,
        reference: u32,
        detail: &'static str,
    },
    InvalidSymbolType {
        kind: &'static str,
        name: String,
        reference: u32,
        detail: &'static str,
    },
    Cycle {
        type_id: u32,
    },
    UnsupportedLayout {
        type_id: u32,
        detail: &'static str,
    },
    Missing {
        kind: &'static str,
        name: String,
    },
    Ambiguous {
        kind: &'static str,
        name: String,
        candidates: usize,
    },
    InvalidSection {
        section: u16,
        offset: u32,
    },
}
impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Open { path, .. } => write!(f, "open PDB: {}", path.display()),
            Self::Parse { operation, detail } => write!(f, "{operation}: {detail}"),
            Self::InvalidUtf8 { operation } => write!(f, "{operation}: name is not UTF-8"),
            Self::UnsupportedPrimitive { index } => {
                write!(f, "unsupported primitive type index 0x{index:x}")
            }
            Self::UnsupportedMachine { machine } => {
                write!(f, "unsupported PDB machine 0x{machine:x}")
            }
            Self::InvalidReference {
                owner,
                reference,
                detail,
            } => write!(
                f,
                "invalid type reference 0x{reference:x} from 0x{owner:x}: {detail}"
            ),
            Self::InvalidSymbolType {
                kind,
                name,
                reference,
                detail,
            } => write!(
                f,
                "invalid {kind} type 0x{reference:x} for {name}: {detail}"
            ),
            Self::Cycle { type_id } => {
                write!(f, "cyclic field-list continuation at 0x{type_id:x}")
            }
            Self::UnsupportedLayout { type_id, detail } => {
                write!(f, "unsupported layout at 0x{type_id:x}: {detail}")
            }
            Self::Missing { kind, name } => write!(f, "missing {kind}: {name}"),
            Self::Ambiguous {
                kind,
                name,
                candidates,
            } => write!(f, "ambiguous {kind} {name}: {candidates} candidates"),
            Self::InvalidSection { section, offset } => {
                write!(f, "invalid section {section} for offset 0x{offset:x}")
            }
        }
    }
}
impl StdError for Error {
    fn source(&self) -> Option<&(dyn StdError + 'static)> {
        match self {
            Self::Open { source, .. } => Some(source.as_ref()),
            _ => None,
        }
    }
}