use std::os::raw::c_int;
use fig_core::diagnostics::{Cause, Code, Warning as CoreWarning};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum WarningCode {
CommentDropped,
CommentStyleDegraded,
ValueDropped,
TypeDegraded,
Unknown(c_int),
}
impl WarningCode {
fn from_core(c: Code) -> Self {
match c {
Code::CommentDropped => WarningCode::CommentDropped,
Code::CommentStyleDegraded => WarningCode::CommentStyleDegraded,
Code::ValueDropped => WarningCode::ValueDropped,
Code::TypeDegraded => WarningCode::TypeDegraded,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum WarningCause {
FormatLimitation,
ExplicitOption,
Unknown(c_int),
}
impl WarningCause {
fn from_core(c: Cause) -> Self {
match c {
Cause::FormatLimitation => WarningCause::FormatLimitation,
Cause::ExplicitOption => WarningCause::ExplicitOption,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Warning {
pub code: WarningCode,
pub cause: WarningCause,
pub path: String,
pub note: String,
}
impl Warning {
pub(crate) fn from_core(w: &CoreWarning) -> Self {
Warning {
code: WarningCode::from_core(w.code),
cause: WarningCause::from_core(w.cause),
path: String::from_utf8_lossy(&w.path).into_owned(),
note: w.note.to_owned(),
}
}
}