6 releases (breaking)

0.5.1 Feb 14, 2023
0.5.0 Feb 13, 2023
0.4.1 Sep 1, 2022
0.3.0 Jul 1, 2022
0.1.0 May 6, 2022

#82 in Operating systems

Download history 21/week @ 2023-06-03 10/week @ 2023-06-10 48/week @ 2023-06-17 34/week @ 2023-06-24 49/week @ 2023-07-01 25/week @ 2023-07-08 58/week @ 2023-07-15 41/week @ 2023-07-22 19/week @ 2023-07-29 29/week @ 2023-08-05 28/week @ 2023-08-12 23/week @ 2023-08-19 20/week @ 2023-08-26 19/week @ 2023-09-02 40/week @ 2023-09-09 25/week @ 2023-09-16

108 downloads per month
Used in 4 crates (3 directly)

GPL-3.0-or-later

125KB
2K SLoC

RUST-APT

rust-apt provides bindings to libapt-pkg.

Currently there is only basic package querying. The goal is to eventually have all of the functionality that python-apt has.

This Crate is Under Active Development

This API is far from what could be considered stable. If you plan on using it in a real project make sure to pin the exact version. Breaking changes will be frequent and potentially unnannouned as the API comes together.

Each module has a raw submodule containing c++ bindings to libapt-pkg.

These are safe to use in terms of memory, but may cause segfaults if you do something wrong.

If you find a way to segfault without using the libapt-pkg bindings directly, please report this as a bug.

Documentation and Examples

For more instructions on how to use rust-apt see our crates.io page.

Getting packages

The cache.packages() method is an iterator of all packages that can be sorted with the PackageSort struct.

Here is how you could iterate over packages that are upgradable. They will also be sorted by name using the .names() method on PackageSort

use rust_apt::cache::{Cache, PackageSort};

let cache = Cache::new();
let sort = PackageSort::default().upgradable().names();

for pkg in cache.packages(&sort) {
	println!(
		"Package: {} {} is upgradable to {}",
		pkg.name(),
		pkg.installed().unwrap().version(),
		pkg.candidate().unwrap().version(),
	);
}

License Note

This crate is licensed under the GPLv3 or later.

Building

libapt-pkg-dev must be installed.

Thread safety

It is not advised to use this crate in multiple threads.

You're free to try it but development will not be focused on making this crate thread safe.

Development

Make sure cargo and rustup are installed before you run the following commands.

You will need the stable and nightly toolchain. Nightly is only used for rustfmt.

Install just, a command runner we use to simplify some tasks.

cargo install just

Now that cargo and just are installed, You can setup your dev environment.

setup-dev will:

  • Install the necessary dependencies with apt.

  • Ensure the proper toolchains are installed with rustup.

  • Create compile_commands.json with bear for better c++ linting

just setup-dev

Before you commit, check formatting and basic code QA.

just fmt
just check

Dependencies

~0.6–1.5MB
~29K SLoC