Library API
How to integrate Zoi's package management features into your own Rust applications.
Zoi is not just a command-line tool; it's also a Rust library that you can use to programmatically install and manage packages. This allows you to embed Zoi's powerful package management capabilities directly into your own applications, such as custom development tools, game launchers, or server deployment scripts.
Getting Started
To use Zoi as a library, add it as a dependency in your project:
cargo add zoi
Or in your Cargo.toml
file:
[dependencies]
zoi = "5.0.0-beta" # subject to change
Core Functions
These are the primary functions for managing packages.
install
Install a new package.
uninstall
Remove an installed package.
update
Update an existing package.
upgrade
Upgrade the Zoi binary itself.
sync
Synchronize the local package database.
autoremove
Remove unused dependencies.
Information & Querying
These functions help you query the state of packages.
resolve_package
Get package metadata without installing.
is_package_installed
Check if a package is installed.
get_installed_packages
List all installed packages.
get_all_available_packages
List all packages in the database.
Pinning
These functions allow you to manage package version pinning.
pin
Pin a package to a specific version.
unpin
Unpin a package.
get_pinned_packages
List all pinned packages.
install
function
This function handles the entire installation process for a given package.
Signature
pub fn install(
source: &str,
mode: InstallMode,
force: bool,
reason: InstallReason,
non_interactive: bool,
) -> Result<(), Box<dyn std::error::Error>>
Parameters
Parameter | Type | Description |
---|---|---|
source | &str | The identifier for the package to install. This can be a package name (e.g. "hello" ), a path to a local .pkg.lua file, or a URL to a package definition. |
mode | InstallMode | An enum that specifies the preferred installation method. |
force | bool | If true , Zoi will reinstall the package even if it is already present. |
reason | InstallReason | An enum indicating why the package is being installed. This is typically Direct for user-initiated installs. |
non_interactive | bool | If true , Zoi will automatically answer "yes" to any confirmation prompts, making the installation non-interactive. |
uninstall
function
Removes a package that was previously installed by Zoi.
Signature
pub fn uninstall(package_name: &str) -> Result<(), Box<dyn std::error::Error>>
update
function
This function checks if a package has a new version available and updates it.
Signature
pub fn update(
source: &str,
non_interactive: bool,
) -> Result<UpdateResult, Box<dyn std::error::Error>>
upgrade
function
Upgrades the Zoi binary itself to the latest version available on GitLab.
Signature
pub fn upgrade(force: bool) -> Result<(), Box<dyn std::error::Error>>
sync
function
Downloads or updates the package database from the remote repository.
Signature
pub fn sync(verbose: bool) -> Result<(), Box<dyn std::error::Error>>
autoremove
function
Removes packages that were installed as dependencies but are no longer needed.
Signature
pub fn autoremove(non_interactive: bool) -> Result<(), Box<dyn Error>>
resolve_package
function
Finds a package and returns its metadata without installing it.
Signature
pub fn resolve_package(source: &str) -> Result<Package, Box<dyn Error>>
is_package_installed
function
Checks if a package is installed in a given scope.
Signature
pub fn is_package_installed(
package_name: &str,
scope: Scope,
) -> Result<Option<InstallManifest>, Box<dyn Error>>
get_installed_packages
function
Returns a list of all packages installed by Zoi.
Signature
pub fn get_installed_packages() -> Result<Vec<InstallManifest>, Box<dyn Error>>
get_all_available_packages
function
Returns a list of all packages available in the active repositories.
Signature
pub fn get_all_available_packages() -> Result<Vec<Package>, Box<dyn Error>>
pin
function
Pins a package to a specific version, preventing it from being updated.
Signature
pub fn pin(package_name: &str, version: &str) -> Result<(), Box<dyn Error>>
unpin
function
Unpins a package, allowing it to be updated again.
Signature
pub fn unpin(package_name: &str) -> Result<(), Box<dyn Error>>
get_pinned_packages
function
Returns a list of all currently pinned packages.
Signature
pub fn get_pinned_packages() -> Result<Vec<PinnedPackage>, Box<dyn Error>>
For complete, runnable examples, please see the Library Examples page.
Last updated on