pub trait PackageManager: Send + Sync {
// Required methods
fn name(&self) -> String;
fn install(
&self,
context: &Context,
package: &InstallationEntry,
) -> Result<()>;
fn uninstall(
&self,
context: &Context,
package: &InstallationEntry,
) -> Result<()>;
fn get_all_explicit(
&self,
context: &Context,
) -> Result<Vec<(String, String)>>;
// Provided method
fn post_install(&self, _context: &Context) -> Result<()> { ... }
}
Expand description
A package manager which gets a darling implementation. This provides the core functionality on how to install,
uninstall, and list packages through darling. Most of these methods when implemented commonly use
std::process::Command
to install things through shell commands. In the rare case that a Rust API is available
and advantageous for a particular package manager, that of course could be used as well.
Required Methods§
Sourcefn name(&self) -> String
fn name(&self) -> String
Returns the name of this package manager. This is a unique all-lowercase identifier that should not conflict
with any others. It’s common to make this the name of the crate, without the darling-
prefix. For example,
this could return "example".to_owned()
, and the crate would be called darling-example
.
TODO: This may change into returning a &'static str
. This might be easier to handle on the receiving end
(such as not having to borrow a value that’s already borrowed, and we can convert it to owned when necessary),
but more importantly, it’d help reinforce that this should be an unchanging constant compile-time known value.
I set this as an owned String
because they’re just generally easier to work with and is the common convention
for method returns, but if there aren’t any bad ramifications then this option should be considered.
Sourcefn install(&self, context: &Context, package: &InstallationEntry) -> Result<()>
fn install(&self, context: &Context, package: &InstallationEntry) -> Result<()>
Installs a package with the given version. If no version is supplied, this should install the latest version. Note that this does not affect the cache file. This simply supplies the system package install command.
§Parameters
context
- The darling context, which provides global immutable information about the program.package
- The name of the package to install.
§Returns
An error if the package could not be installed.
Sourcefn uninstall(
&self,
context: &Context,
package: &InstallationEntry,
) -> Result<()>
fn uninstall( &self, context: &Context, package: &InstallationEntry, ) -> Result<()>
Uninstalls a package from the system. This does not affect the cache file, it simply removes the package
from the system itself, and darling-core
will handle removing the package from the cache file.
§Parameters
context
- The darling context, which provides global immutable information about the program.package
- The name of the package to remove.
§Returns
An error if the package could not be removed.
Sourcefn get_all_explicit(&self, context: &Context) -> Result<Vec<(String, String)>>
fn get_all_explicit(&self, context: &Context) -> Result<Vec<(String, String)>>
Returns all explicitly installed packages on the system; That is, packages which are not dependencies of
other packages. This should not read from a darling file; Instead, darling uses this method to update
the file when running darling require-all
§Parameters
context
- The darling context, which provides global immutable information about the program.
§Returns
The name and version of each installed package. as a Vec<(name: String, version: String)>
.
Provided Methods§
Sourcefn post_install(&self, _context: &Context) -> Result<()>
fn post_install(&self, _context: &Context) -> Result<()>
This is run after a single or group of packages are installed. The difference between placing code here and in
[install] is that when running commands like load-installed
, which load all installed packages into the
darling config file, this is only run once after all packages are installed, instead of every time an individual
package is installed.
This is useful for modules such as the core module which needs to rebuild the source code every time a new module is added. With this system, we can just rebuild the source once after all of the modules are added, instead of every time each individual module is added.
Note that this will still be run for individual installations after the [install] method.
This method is optional, and has a default implementation of just Ok(())
.
§Parameters
context
- The darling context, which provides global immutable information about the program.
§Returns
An error if anything went wrong in the post-installation process. This is different module-to-module so no more information than this can be specified here.