Struct Offline

Source
pub struct Offline { /* private fields */ }
Expand description

Dependency solver ready for offline use cases.

The Offline struct has to be initialized with the path to ELM_HOME, as well as the version of elm used (concretely, this should only be "0.19.1" for now). Then it provides a solve_deps function, which will either succeed and return a solution, or fail with an error.

The offline solver will only ever look for packages inside ELM_HOME and thus should work with other “elm-compatible” ecosystems such as Lamdera. You can use it as follows.

// Define an offline solver.
let offline_solver = solver::Offline::new(elm_home(), "0.19.1");

// Load the project elm.json.
let elm_json_str = std::fs::read_to_string("elm.json")
    .expect("Are you in an elm project? there was an issue loading the elm.json");
let project_elm_json = serde_json::from_str(&elm_json_str)
    .expect("Failed to decode the elm.json");

// Solve with tests dependencies.
let use_test = true;

// Do not add any extra additional dependency.
let extras = &[];

// Solve dependencies.
let solution = offline_solver
    .solve_deps(&project_elm_json, use_test, extras)
    .expect("Dependency solving failed");

Note that it is possible to provide additional package constraints, which is convenient for tooling when requiring additional packages that are not recorded directly in the original elm.json file.

Implementations§

Source§

impl Offline

Source

pub fn new<PB: Into<PathBuf>, S: ToString>(elm_home: PB, elm_version: S) -> Self

Constructor for the offline solver.

The elm_home argument will typically be /home/user/.elm. The elm_version argument should be “0.19.1” as it is currently the only version supported.

Source

pub fn solve_deps( &self, project_elm_json: &ProjectConfig, use_test: bool, additional_constraints: &[(Pkg, Constraint)], ) -> Result<AppDependencies, PubGrubError<Pkg, SemVer>>

Run the dependency solver on a given project config, obtained from an elm.json.

Set use_test to false to solve the normal dependencies or to true to also take into account the test dependencies.

Additional dependencies can be specified for convenience when they are not specified directly in the project config, as follows.

let extra = &[(
  Pkg::new("jfmengels", "elm-review"),
  Constraint(Range::between( (2,6,1), (3,0,0) )),
)];

Trait Implementations§

Source§

impl Clone for Offline

Source§

fn clone(&self) -> Offline

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Offline

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.