Skip to main content

Store

Struct Store 

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

A store directory: the workspaces and profiles of one installation.

Implementations§

Source§

impl Store

Source

pub fn new(root: impl Into<PathBuf>) -> Self

The store at root. Nothing is read or written until it is asked for.

Source

pub fn root(&self) -> &Path

The store directory itself.

Source

pub fn profiles_dir(&self) -> PathBuf

The folder the profile definitions live in.

Source

pub fn workspaces_dir(&self) -> PathBuf

The folder the workspaces live in.

Source

pub fn prepare(&self) -> Result<(), Diagnostic>

Creates the folders the store needs, and proves they can be written.

Safe to call at every start: a store that is already there is left alone.

§Errors

A diagnostic naming the directory and the reason, when it cannot be created or written.

Source

pub fn adopt(&self) -> Vec<Diagnostic>

Gives every name this store carries from an older QCode the name it has today: Projects/ becomes Workspaces/, and inside each workspace project.qcode becomes workspace.qcode, Project/ and then Code/ become Work/, and Backup/Project.git becomes Backup/Code.git.

Each move is a single rename, so an interruption leaves the old name whole rather than two halves, and nothing is renamed onto something that is there already: a store holding both names is left as it is and said. Safe to call at every start — a store with none of the old names only looks.

Source

pub fn workspace_paths(&self, id: &WorkspaceId) -> WorkspacePaths

Where everything of the workspace id is, whether or not it exists yet.

Source

pub fn paths_of(&self, file: &WorkspaceFile) -> WorkspacePaths

Where everything of the workspace file describes is: Store::workspace_paths, with the person’s own folder as the code folder when the workspace works in one where it stands.

Everything that opens a workspace reads its folders from here, so the file tree, the shell, every container’s work folder and the backup all see the same folder.

Source

pub fn create_workspace( &self, name: &str, created: Date, ) -> Result<WorkspaceFile, NewWorkspaceError>

Makes a workspace the user called name and gives it the tree of the design.

§Errors

NewWorkspaceError::Name when the name yields no identifier, NewWorkspaceError::Taken when a folder of that identifier is already there — including one that only differs in case, which a file system that ignores case would treat as the same folder — and NewWorkspaceError::Blocked when the store cannot be written.

Source

pub fn create_workspace_in( &self, name: &str, created: Date, folder: Option<PathBuf>, ) -> Result<WorkspaceFile, NewWorkspaceError>

Makes a workspace the user called name that works in folder where it stands, or in a Work/ of its own when folder is None.

The person’s folder is only named in the workspace file: nothing is made, moved or written in it.

§Errors

As Store::create_workspace.

Source

pub fn write_workspace(&self, file: &WorkspaceFile) -> Result<(), Diagnostic>

Writes a workspace’s workspace.qcode atomically and makes sure its folders — including one per profile it names — are there.

§Errors

A diagnostic naming the directory or file that could not be written.

Source

pub fn read_workspace(&self, id: &WorkspaceId) -> Loaded<Option<WorkspaceFile>>

Reads one workspace’s workspace.qcode.

Source

pub fn workspaces(&self) -> Loaded<Vec<WorkspaceEntry>>

Every workspace folder of the store, sorted by folder name.

A folder that is broken or half-made is listed with its problems rather than left out: the user cannot repair what the list refuses to show. A store that cannot be read at all yields an empty list and one diagnostic.

Source

pub fn profiles(&self) -> Loaded<Vec<Profile>>

Every profile definition of the store, sorted by file name.

A Profiles/ folder that is not there yet is not a problem: it means no profiles. A file that cannot be read or cannot be understood is reported and the rest are still returned, so one broken definition never hides the profiles that work.

Custom profiles live in Store::custom_profiles_dir, which is read as well: their parts are their own, and a QCode older than that folder does not see them at all.

Source

pub fn custom_profiles_dir(&self) -> PathBuf

The folder a custom profile’s definition file is in.

Source

pub fn profile_file(&self, profile: &Profile) -> PathBuf

The folder profile’s definition file is in, and its name: a ready-made template’s is the one every profile’s file has always been in, and a custom one’s is the folder of its own, which a QCode that does not know it never reads.

Source

pub fn write_profile(&self, profile: &Profile) -> Result<(), Diagnostic>

Writes a profile’s definition file atomically, making the store’s folders first, and takes away the file of the kind it is not: a profile has one definition, whichever folder holds it, and two of them would list it twice.

§Errors

A diagnostic naming the folder or file that could not be written.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Store

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Store

Source§

impl PartialEq for Store

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Store

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.