rust_apt/
lib.rs

1//! rust-apt provides bindings to `libapt-pkg`.
2//! The goal is to eventually have all of the functionality of `python-apt`
3//!
4//! The source repository is <https://gitlab.com/volian/rust-apt>
5//! For more information please see the readme in the source code.
6//!
7//! Each module has a `raw` submodule containing c++ bindings to `libapt-pkg`
8//!
9//! These are safe to use in terms of memory,
10//! but may cause segfaults if you do something wrong.
11//!
12//! If you find a way to segfault without using the `libapt-pkg` bindings
13//! directly, please report this as a bug.
14
15// Clippy is really mad at my safety docs and idk why
16#![allow(clippy::missing_safety_doc)]
17
18#[macro_use]
19mod macros;
20mod acquire;
21pub mod cache;
22pub mod config;
23mod depcache;
24pub mod error;
25mod iterators;
26mod pkgmanager;
27pub mod progress;
28pub mod records;
29pub mod tagfile;
30pub mod util;
31
32#[doc(inline)]
33pub use cache::{Cache, PackageSort};
34pub use iterators::dependency::{create_depends_map, BaseDep, DepFlags, DepType, Dependency};
35pub use iterators::files::{PackageFile, VersionFile};
36pub use iterators::package::{Package, PkgCurrentState, PkgInstState, PkgSelectedState};
37pub use iterators::provider::Provider;
38pub use iterators::version::Version;
39
40/// C++ bindings for libapt-pkg
41pub mod raw {
42	pub use crate::acquire::raw::{
43		acquire_status, create_acquire, AcqTextStatus, AcqWorker, Item, ItemDesc, ItemState,
44		PkgAcquire,
45	};
46	pub use crate::cache::raw::{create_cache, PkgCacheFile};
47	pub use crate::depcache::raw::{ActionGroup, PkgDepCache};
48	pub use crate::iterators::{
49		DepIterator, DescIterator, PkgFileIterator, PkgIterator, PrvIterator, VerFileIterator,
50		VerIterator,
51	};
52	pub use crate::pkgmanager::raw::{
53		create_pkgmanager, create_problem_resolver, PackageManager, ProblemResolver,
54	};
55	pub use crate::records::raw::{IndexFile, Parser, PkgRecords};
56	pub use crate::util::raw::*;
57	// Hmm, maybe this is reason enough to make a wrapper in C++
58	// So that the raw functions are methods on a "Config" struct?
59	// But it may need to not outlive the cache if we do that.
60	pub mod config {
61		pub use crate::config::raw::*;
62	}
63
64	/// Iterator trait for libapt raw bindings
65	pub trait IntoRawIter {
66		type Item;
67		fn raw_iter(self) -> Self::Item;
68
69		fn make_safe(self) -> Option<Self>
70		where
71			Self: Sized;
72
73		fn to_vec(self) -> Vec<Self>
74		where
75			Self: Sized;
76	}
77
78	use cxx::UniquePtr;
79	use paste::paste;
80
81	raw_iter!(
82		PkgIterator,
83		VerIterator,
84		DepIterator,
85		PrvIterator,
86		VerFileIterator,
87		DescIterator,
88		PkgFileIterator
89	);
90}
91
92use depcache::DepCache;
93use error::AptErrors;
94use records::PackageRecords;
95
96impl_deref!(
97	Cache -> raw::PkgCacheFile,
98	DepCache -> raw::PkgDepCache,
99	PackageRecords -> raw::PkgRecords,
100	AptErrors -> Vec<error::raw::AptError>,
101	Package<'a> -> raw::PkgIterator,
102	Version<'a> -> raw::VerIterator,
103	Dependency<'a> -> Vec<BaseDep<'a>>,
104	BaseDep<'a> -> raw::DepIterator,
105	Provider<'a> -> raw::PrvIterator,
106	VersionFile<'a> -> raw::VerFileIterator,
107	PackageFile<'a> -> raw::PkgFileIterator,
108);
109
110// Version is omitted because it has special needs
111impl_partial_eq!(
112	Package<'a>,
113	BaseDep<'a>,
114	Provider<'a>,
115	VersionFile<'a>,
116	PackageFile<'a>,
117);
118
119impl_hash_eq!(
120	Package<'a>,
121	Version<'a>,
122	BaseDep<'a>,
123	Provider<'a>,
124	VersionFile<'a>,
125	PackageFile<'a>,
126);