Skip to main content

alpm_db/db/
traits.rs

1//! Traits relevant for interfacing with an [alpm-db].
2//!
3//! [alpm-db]: https://alpm.archlinux.page/specifications/alpm-db.7.html
4
5use std::fmt::Debug;
6
7use alpm_mtree::mtree::MtreeTransfer;
8use alpm_types::EntryName;
9
10use crate::{desc::DbDescFile, files::DbFiles};
11
12/// An interface for retrieving data for an entry that should be persisted in an [alpm-db].
13///
14/// An [`Entry`][crate::db::Entry] consists of a directory and several component files.
15/// As such, the [`EntrySource`] interface provides access to all relevant data to create an entry
16/// in an [alpm-db]:
17///
18/// - the name of the entry
19/// - the [alpm-db-desc] data
20/// - the [alpm-db-files] data
21/// - the [ALPM-MTREE] file
22/// - the optional [alpm-install-scriptlet] data
23///
24/// [ALPM-MTREE]: https://alpm.archlinux.page/specifications/ALPM-MTREE.5.html
25/// [alpm-db]: https://alpm.archlinux.page/specifications/alpm-db.7.html
26/// [alpm-db-desc]: https://alpm.archlinux.page/specifications/alpm-db-desc.5.html
27/// [alpm-db-files]: https://alpm.archlinux.page/specifications/alpm-db-files.5.html
28/// [alpm-install-scriptlet]: https://alpm.archlinux.page/specifications/alpm-install-scriptlet.5.html
29pub trait EntrySource: Debug {
30    /// Returns a reference to the [`EntryName`] of the implementation.
31    fn entry_name(&self) -> EntryName;
32
33    /// Returns the [alpm-db-desc] data of the implementation.
34    ///
35    /// [alpm-db-desc]: https://alpm.archlinux.page/specifications/alpm-db-desc.5.html
36    fn alpm_db_desc(&self) -> Result<DbDescFile, crate::Error>;
37
38    /// Returns the [alpm-db-files] data of the implementation.
39    ///
40    /// [alpm-db-files]: https://alpm.archlinux.page/specifications/alpm-db-files.5.html
41    fn alpm_db_files(&self) -> Result<DbFiles, crate::Error>;
42
43    /// Returns the transferable [ALPM-MTREE] data of the implementation.
44    ///
45    /// [ALPM-MTREE]: https://alpm.archlinux.page/specifications/ALPM-MTREE.5.html
46    fn alpm_mtree(&self) -> Result<MtreeTransfer, crate::Error>;
47
48    /// Returns the optional [alpm-install-scriptlet] data of the implementation.
49    ///
50    /// [alpm-install-scriptlet]: https://alpm.archlinux.page/specifications/alpm-install-scriptlet.5.html
51    fn alpm_install_scriptlet(&self) -> Result<Option<String>, crate::Error>;
52}