pdb-bindgen-codegen 0.1.0

Build-time discovery, PDB acquisition, and binding generation for pdb-bindgen.
Documentation
use crate::PdbFilenameErrorKind;
use std::error::Error;
use std::fmt;

/// Describes a configuration validation failure.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ConfigError {
    /// A logical PDB filename is invalid.
    InvalidPdbFilename {
        /// The rejected filename.
        filename: String,
        /// The validation failure category.
        reason: PdbFilenameErrorKind,
    },
    /// A logical image key is empty.
    EmptyImageKey,
    /// A directly supplied local PDB path is empty.
    EmptyLocalPdbPath,
    /// A cache directory path is empty.
    EmptyCachePath,
    /// A logical image key is already present.
    DuplicateImageKey {
        /// The duplicate exact key.
        key: String,
    },
    /// A Symbol Server URL is invalid.
    InvalidSymbolServer {
        /// The rejected URL.
        url: String,
        /// The validation failure category.
        reason: SymbolServerErrorKind,
    },
    /// A source root path is empty.
    EmptySourceRoot,
    /// A custom cfg atom name is not one Rust cfg identifier.
    InvalidCfgName {
        /// The rejected cfg name.
        name: String,
    },
}

impl fmt::Display for ConfigError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidPdbFilename { filename, reason } => {
                write!(
                    formatter,
                    "invalid logical PDB filename {filename:?}: {reason}"
                )
            }
            Self::EmptyImageKey => formatter.write_str("image key must not be empty"),

            Self::EmptyLocalPdbPath => formatter.write_str("local PDB path must not be empty"),
            Self::EmptyCachePath => formatter.write_str("cache directory must not be empty"),
            Self::DuplicateImageKey { key } => write!(formatter, "duplicate image key {key:?}"),
            Self::InvalidSymbolServer { url, reason } => {
                write!(formatter, "invalid Symbol Server URL {url:?}: {reason}")
            }
            Self::EmptySourceRoot => formatter.write_str("source root path must not be empty"),
            Self::InvalidCfgName { name } => write!(
                formatter,
                "invalid cfg name {name:?}: expected one Rust cfg identifier"
            ),
        }
    }
}

impl Error for ConfigError {}

/// Describes why a Symbol Server URL is invalid.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum SymbolServerErrorKind {
    /// The URL does not start with `http://` or `https://`.
    Scheme,
    /// The URL has no authority after its scheme.
    MissingAuthority,
    /// The URL contains characters not accepted by this configuration layer.
    InvalidCharacter,
}

impl fmt::Display for SymbolServerErrorKind {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str(match self {
            Self::Scheme => "expected an http:// or https:// URL",
            Self::MissingAuthority => "server authority must not be empty",
            Self::InvalidCharacter => {
                "ASCII whitespace, control characters, queries, and fragments are not allowed"
            }
        })
    }
}