apksigner 1.0.0

APK signer and verifier CLI — a faithful Rust port of AOSP apksigner
//! Mirrors `com.android.apksigner.ParameterException`.
//!
//! Indicates that there is an issue with the command-line parameters provided to the tool.

use std::fmt;

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

impl ParameterException {
    pub fn new(message: impl Into<String>) -> Self {
        ParameterException {
            message: message.into(),
        }
    }
}

impl fmt::Display for ParameterException {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.message)
    }
}

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

impl From<ParameterException> for String {
    fn from(e: ParameterException) -> Self {
        e.message
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn displays_its_message() {
        let e = ParameterException::new("boom");
        assert_eq!(e.to_string(), "boom");
    }
}