Zillowe FoundationZillowe Documentation

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.

Information & Querying

These functions help you query the state of packages.

Pinning

These functions allow you to manage package version pinning.


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

ParameterTypeDescription
source&strThe 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.
modeInstallModeAn enum that specifies the preferred installation method.
forceboolIf true, Zoi will reinstall the package even if it is already present.
reasonInstallReasonAn enum indicating why the package is being installed. This is typically Direct for user-initiated installs.
non_interactiveboolIf 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