rustympkglib/lib.rs
1//! A _rusty_ (and very much incomplete) crate library for dealing with Arch Linux's `PKGBUILD`
2//! files and implement some of `makepkg`'s (or related tools) functionality.
3//!
4//! This crate so far can only parse certain key variables and arrays in a PKGBUILD file. In the
5//! near future it will also be able to edit those key variables and write it back into the
6//! PKGBUILD.
7use std::fmt;
8
9mod helpers;
10pub mod pkgbuild;
11pub mod pkgdata;
12
13/// A list of possible PKGBUILD/makepkg error kinds used in `rustympkglib`.
14#[derive(Debug, PartialEq, Eq)]
15#[non_exhaustive]
16#[allow(clippy::upper_case_acronyms)]
17pub enum ErrorKind {
18 /// Error trying to validate some field or value. For example: `pkgname`s that contain illegal
19 /// characters.
20 ValidationError,
21 /// Error trying to parse the given PKGBUILD file. This error happens at the parsing level, so
22 /// chances are it'll be something illegal with the file or the Bash code within.
23 ParseError,
24 /// Error used when the PKGBUILD file could be parsed, but it doesn't follow the documentation
25 /// on things such as containing all the required fields.
26 InvalidPKGBUILDError,
27}
28
29impl fmt::Display for ErrorKind {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "{:?}", self)
32 }
33}
34
35/// Error interface used across `rustympkglib`.
36#[derive(Debug, PartialEq, Eq)]
37pub struct Error {
38 pub kind: ErrorKind,
39 pub msg: String,
40}
41
42impl Error {
43 pub fn new(kind: ErrorKind, msg: &str) -> Error {
44 Error {
45 kind,
46 msg: msg.to_string(),
47 }
48 }
49}
50
51impl fmt::Display for Error {
52 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53 write!(f, "{}: {}", self.kind, self.msg)
54 }
55}