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::{BaseDep, DepFlags, DepType, Dependency, create_depends_map};
35pub use iterators::files::{PackageFile, VersionFile};
36pub use iterators::package::{Marked, 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		AcqTextStatus, AcqWorker, Item, ItemDesc, ItemState, PkgAcquire, acquire_status,
44		create_acquire,
45	};
46	pub use crate::cache::raw::{PkgCacheFile, create_cache};
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		PackageManager, ProblemResolver, create_pkgmanager, create_problem_resolver,
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
80	raw_iter!(
81		PkgIterator => IterPkgIterator,
82		VerIterator => IterVerIterator,
83		DepIterator => IterDepIterator,
84		PrvIterator => IterPrvIterator,
85		VerFileIterator => IterVerFileIterator,
86		DescIterator => IterDescIterator,
87		PkgFileIterator => IterPkgFileIterator,
88	);
89}
90
91use depcache::DepCache;
92use error::AptErrors;
93use records::PackageRecords;
94
95impl_deref!(
96	Cache -> raw::PkgCacheFile,
97	DepCache -> raw::PkgDepCache,
98	PackageRecords -> raw::PkgRecords,
99	AptErrors -> Vec<error::raw::AptError>,
100	Package<'a> -> raw::PkgIterator,
101	Version<'a> -> raw::VerIterator,
102	Dependency<'a> -> Vec<BaseDep<'a>>,
103	BaseDep<'a> -> raw::DepIterator,
104	Provider<'a> -> raw::PrvIterator,
105	VersionFile<'a> -> raw::VerFileIterator,
106	PackageFile<'a> -> raw::PkgFileIterator,
107);
108
109// Version is omitted because it has special needs
110impl_partial_eq!(
111	Package<'a>,
112	BaseDep<'a>,
113	Provider<'a>,
114	VersionFile<'a>,
115	PackageFile<'a>,
116);
117
118impl_hash_eq!(
119	Package<'a>,
120	Version<'a>,
121	BaseDep<'a>,
122	Provider<'a>,
123	VersionFile<'a>,
124	PackageFile<'a>,
125);