pub struct Package<'a> { /* private fields */ }Expand description
A struct representing an apt Package
Implementations
sourceimpl<'a> Package<'a>
impl<'a> Package<'a>
sourcepub fn fullname(&self, pretty: bool) -> String
pub fn fullname(&self, pretty: bool) -> String
Get the fullname of the package.
Pretty is a bool that will omit the native arch.
For example on an amd64 system:
use rust_apt::cache::Cache;
let cache = Cache::new();
if let Some(pkg) = cache.get("apt") {
// Prints just "apt"
println!("{}", pkg.fullname(true));
// Prints "apt:amd64"
println!("{}", pkg.fullname(false));
};
if let Some(pkg) = cache.get("apt:i386") {
// Prints "apt:i386" for the i386 package
println!("{}", pkg.fullname(true));
};sourcepub fn current_state(&self) -> u8
pub fn current_state(&self) -> u8
The current state of the package.
sourcepub fn inst_state(&self) -> u8
pub fn inst_state(&self) -> u8
The installed state of the package.
sourcepub fn selected_state(&self) -> u8
pub fn selected_state(&self) -> u8
The selected state of the package.
sourcepub fn has_versions(&self) -> bool
pub fn has_versions(&self) -> bool
Check if the package has versions.
sourcepub fn has_provides(&self) -> bool
pub fn has_provides(&self) -> bool
Check if the package has provides.
sourcepub fn rev_provides_list(
&self,
version_rel: Option<(&str, &str)>
) -> Vec<Version<'_>>
pub fn rev_provides_list(
&self,
version_rel: Option<(&str, &str)>
) -> Vec<Version<'_>>
The list of packages that provide this package.
version_rel:
- Some = A tuple representing the version and operator (i.e.
("1.0.0", ">=")). - None = No version/operator qualifier will be used.
If an invalid operator is passed when using the Some variant
(anything other than <<, <=, =, >=, and >>), than this
function will panic.
This function searches the cache for any packages that provide this package. It is meant to get the list of packages that satisfy a dependency string. Take this example from a control file:
\# Example 1:
Depends: apt-transport-https (= 5)
\# Example 2:
Depends: apt-transport-httpsIf version_rel is None, then any packages that contain Provides: apt-transport-https will be unable to satisfy example 1, as per Debian policy.
If version_rel is Some on the other hand, then this function will
make sure any packages matching the provides entry (i.e. Provides: apt-transport-https (= 5)) fit into the version requirement. E.g. if
(">=", "6.0.0") was provided, then the previous example of Provides: apt-transport-https (= 5) would not be returned, since it didn’t fit
the requirements of being greater than or equal to 6.0.0.
Returns:
A vector of matching Version structs.
If you need to see what packages this package provides for, use a
version from Package::candidate or Package::versions and call
Version::provides_list instead.
NOTE: This function is currently fairly expensive to run (~300 milliseconds on an Intel i5), and may dramatically slow down your program if called too much.
sourcepub fn candidate(&self) -> Option<Version<'a>>
pub fn candidate(&self) -> Option<Version<'a>>
Returns the version object of the candidate.
If there isn’t a candidate, returns None
sourcepub fn installed(&self) -> Option<Version<'a>>
pub fn installed(&self) -> Option<Version<'a>>
Returns the version object of the installed version.
If there isn’t an installed version, returns None
sourcepub fn get_version(&self, version_str: &str) -> Option<Version<'a>>
pub fn get_version(&self, version_str: &str) -> Option<Version<'a>>
Return either a Version or None
Example:
use rust_apt::cache::Cache;
let cache = Cache::new();
let pkg = cache.get("apt").unwrap();
pkg.get_version("2.4.7");sourcepub fn is_installed(&self) -> bool
pub fn is_installed(&self) -> bool
Check if the package is installed.
sourcepub fn is_upgradable(&self, skip_depcache: bool) -> bool
pub fn is_upgradable(&self, skip_depcache: bool) -> bool
Check if the package is upgradable.
skip_depcache:
Skipping the DepCache is unnecessary if it’s already been initialized.
If you’re unsure use false
sourcepub fn is_auto_installed(&self) -> bool
pub fn is_auto_installed(&self) -> bool
Check if the package is auto installed. (Not installed by the user)
sourcepub fn is_auto_removable(&self) -> bool
pub fn is_auto_removable(&self) -> bool
Check if the package is auto removable
sourcepub fn is_now_broken(&self) -> bool
pub fn is_now_broken(&self) -> bool
Check if the package is now broken
sourcepub fn is_inst_broken(&self) -> bool
pub fn is_inst_broken(&self) -> bool
Check if the package package installed is broken
sourcepub fn marked_install(&self) -> bool
pub fn marked_install(&self) -> bool
Check if the package is marked install
sourcepub fn marked_upgrade(&self) -> bool
pub fn marked_upgrade(&self) -> bool
Check if the package is marked upgrade
sourcepub fn marked_purge(&self) -> bool
pub fn marked_purge(&self) -> bool
Check if the package is marked purge
sourcepub fn marked_delete(&self) -> bool
pub fn marked_delete(&self) -> bool
Check if the package is marked delete
sourcepub fn marked_keep(&self) -> bool
pub fn marked_keep(&self) -> bool
Check if the package is marked keep
sourcepub fn marked_downgrade(&self) -> bool
pub fn marked_downgrade(&self) -> bool
Check if the package is marked downgrade
sourcepub fn marked_reinstall(&self) -> bool
pub fn marked_reinstall(&self) -> bool
Check if the package is marked reinstall
sourcepub fn state(&self, mark: &Mark) -> bool
pub fn state(&self, mark: &Mark) -> bool
Get the state of a package based on a Mark
Returns:
Example
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
let cache = Cache::new();
let pkg = cache.get("apt").unwrap();
if pkg.state(&Mark::Auto) {
println!("Package is automatically installed")
} else {
println!("Package is manually installed")
}sourcepub fn set(&self, mark: &Mark) -> bool
pub fn set(&self, mark: &Mark) -> bool
Set a Mark on a package using the Mark enum
Returns:
Note:
There are some cases where a mark is successful, but nothing will change.
If a package is already installed, at the latest version,
and you mark that package for install you will get true,
but the package will not be altered. get(Mark::Install) will be false
Example
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
let cache = Cache::new();
let pkg = cache.get("apt").unwrap();
if pkg.set(&Mark::Purge) {
println!("Package will be purged")
} else {
println!("Package was unable to be purged")
}sourcepub fn mark_auto(&self, mark_auto: bool) -> bool
pub fn mark_auto(&self, mark_auto: bool) -> bool
sourcepub fn mark_keep(&self) -> bool
pub fn mark_keep(&self) -> bool
Mark a package for keep.
Returns:
This means that the package will not be changed from its current version. This will not stop a reinstall, but will stop removal, upgrades and downgrades
We don’t believe that there is any reason to unmark packages for keep. If someone has a reason, and would like it implemented, please put in a feature request.
sourcepub fn mark_delete(&self, purge: bool) -> bool
pub fn mark_delete(&self, purge: bool) -> bool
sourcepub fn mark_install(&self, auto_inst: bool, from_user: bool) -> bool
pub fn mark_install(&self, auto_inst: bool, from_user: bool) -> bool
Mark a package for installation.
auto_inst:
from_user:
- true = The package will be marked manually installed.
- false = The package will be unmarked automatically installed.
Returns:
If a package is already installed, at the latest version,
and you mark that package for install you will get true,
but the package will not be altered.
pkg.marked_install() will be false
sourcepub fn mark_reinstall(&self, reinstall: bool) -> bool
pub fn mark_reinstall(&self, reinstall: bool) -> bool
sourcepub fn protect(&self)
pub fn protect(&self)
Protect a package’s state
for when crate::cache::Cache::resolve is called.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Package<'a>
impl<'a> !Send for Package<'a>
impl<'a> !Sync for Package<'a>
impl<'a> Unpin for Package<'a>
impl<'a> !UnwindSafe for Package<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more