mod api;
mod field;
pub use api::{AcroFormDocument, FieldValue, FormField};
pub use field::FieldType;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Lopdf(lopdf::Error),
MissingField { field: String },
InvalidFieldType { expected: String, found: String },
Io(std::io::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Lopdf(e) => write!(f, "PDF error: {}", e),
Error::MissingField { field } => write!(f, "Field not found: {}", field),
Error::InvalidFieldType { expected, found } => {
write!(
f,
"Invalid field type: expected {}, found {}",
expected, found
)
}
Error::Io(e) => write!(f, "IO error: {}", e),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Lopdf(e) => Some(e),
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<lopdf::Error> for Error {
fn from(err: lopdf::Error) -> Self {
Error::Lopdf(err)
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Io(err)
}
}