Skip to main content

Crate devset_core

Crate devset_core 

Source
Expand description

Versioned file bundles, applied to a directory and updated without losing local edits.

A profile is a directory of files, on disk or in git; a target is a directory that applies profiles as layers. devset records what it wrote in the target’s .devset/, so a later update tells a local edit from a change the profile made: the edit is kept, and merged with the change where the file’s Policy says so. A profile owns a whole file, or a part of one its Scope names: the keys its payload defines, or a marked block.

§Applying a profile

Every operation is a prefix of one chain, and only commit writes:

use std::fs;

use devset_core::source::Source;
use devset_core::{Cache, Mode, Refresh, Target, commit, plan, resolve, survey};

let dir = camino_tempfile::tempdir()?;
let root = dir.path();
let mut target = Target::open_or_new(&root.join("repo"))?;
target.add_layer(Source::Dir("../base".into()))?;

let resolved = resolve(&target, &Cache::at(root.join("cache")), Refresh::None)?; // read, compose
let survey = survey(resolved, &target)?; // compare with the disk
let plan = plan(survey, Mode::Apply, &target)?; // decide, merge
commit(plan, &target)?; // write, state last

let applied = fs::read_to_string(root.join("repo/.editorconfig"))?;
assert_eq!(applied, "root = true\n", "the profile's file, in the target");

§Updating

Refresh::All moves every layer to what its ref names now; the rest of the chain is the same. A merge file then merges its local edits with the profile’s new version. A conflict leaves the update unfinished, waiting in .devset/conflicts/: a chain under Mode::Continue installs the fix, or a Rollback takes the whole update back.

§Types

  • Target: the directory devset manages, and what its .devset/ records.
  • Resolved: the target’s layers composed, one provider per path.
  • Survey: every managed path as the profile wants it, as recorded, and as on disk.
  • Plan: what committing does to each path.
  • Rollback: an unfinished update, and what taking it back restores.
  • Error: why any of it did not go through, one type per domain.

The files people write have modules of their own: profile for profile.toml, target for .devset/config.toml, and source for where a layer comes from.

Modules§

plan
Deciding what committing does to each path, merges included.
profile
What a profile declares, in its profile.toml.
resolve
Resolving a target’s layers into one Resolved profile: fetched, composed, answered.
source
Where a layer’s profile comes from: a local directory, or a git repository at one commit.
survey
Comparing a target with its resolved profile, path by path.
target
The directory devset manages, and what its .devset/ records.

Structs§

Cache
Fetched git profiles, shared by every target on the machine.
ParseError
A file that does not parse, with the text to point into.
PathError
Why a string is not a RelPath.
Plan
Everything committing will do; nothing is written until commit.
RelPath
A path a profile manages, relative to the target root.
Resolved
A target’s layers, composed: each file has one provider, or one per part, and settings are decided.
Rollback
An unfinished update, and what taking it back does.
Survey
A target’s managed paths against its resolved profile, in path order.
Target
A directory devset manages.

Enums§

Error
Why a devset operation did not go through.
MergeError
Why a merge cannot run, or its resolution cannot be installed.
Mode
How far a plan may go.
ProfileError
Why a profile, or the layers together, do not resolve.
Refresh
Which layers resolve may move off their locked commit.
Revert
What taking a target file back does.
SourceError
Why a source cannot be read.
TargetError
Why a target cannot be found, read or written.
VarError
Why the layers’ variables cannot be answered or rendered.

Constants§

VERSION
This build’s version, which a profile’s devset requirement is checked against.

Functions§

commit
Carries out plan in target, returning its steps.
plan
Decides every path of survey under mode, running the merges it needs.
resolve
Resolves target’s layers into one profile, the target’s overrides and settings on top.
survey
Compares target’s files with resolved.

Type Aliases§

Result
A Result that fails with an Error unless told otherwise.