Struct Editor

Source
pub struct Editor<'repo> {
    pub repo: &'repo Repository,
    /* private fields */
}
Available on crate feature tree-editor only.
Expand description

All state needed to conveniently edit a tree, using only update-or-insert and removals.

Fields§

§repo: &'repo Repository

The owning repository.

Implementations§

Source§

impl<'repo> Editor<'repo>

Lifecycle

Source

pub fn new(tree: &Tree<'repo>) -> Result<Self, Error>

Initialize a new editor from the given tree.

Source

pub fn detach(self) -> Editor<'repo>

Detach all extras and return the underlying plumbing editor, which won’t perform validation when writing the tree.

Source§

impl<'repo> Editor<'repo>

Cursor Handling

Source

pub fn to_cursor(&mut self) -> Cursor<'_, 'repo>

Turn ourselves as a cursor, which points to the same tree as the editor.

This is useful if a method takes a Cursor, not an Editor.

Source

pub fn cursor_at( &mut self, rela_path: impl ToComponents, ) -> Result<Cursor<'_, 'repo>, Error>

Create a cursor at the given rela_path, which must be a tree or is turned into a tree as its own edit.

The returned cursor will then allow applying edits to the tree at rela_path as root. If rela_path is a single empty string, it is equivalent to using the current instance itself.

Source§

impl<'repo> Editor<'repo>

Operations

Source

pub fn set_root(&mut self, root: &Tree<'repo>) -> Result<&mut Self, Error>

Set the root tree of the modification to root, assuring it has a well-known state.

Note that this erases all previous edits.

This is useful if the same editor is re-used for various trees.

Source

pub fn upsert( &mut self, rela_path: impl ToComponents, kind: EntryKind, id: impl Into<ObjectId>, ) -> Result<&mut Self, Error>

Insert a new entry of kind with id at rela_path, an iterator over each path component in the tree, like a/b/c. Names are matched case-sensitively.

Existing leaf-entries will be overwritten unconditionally, and it is assumed that id is available in the object database or will be made available at a later point to assure the integrity of the produced tree.

Intermediate trees will be created if they don’t exist in the object database, otherwise they will be loaded and entries will be inserted into them instead.

Note that id can be null to create a placeholder. These will not be written, and paths leading through them will not be considered a problem.

id can also be an empty tree, along with the respective kind, even though that’s normally not allowed in Git trees.

Validation of path-components will not be performed here, but when writing the tree.

Source

pub fn remove( &mut self, rela_path: impl ToComponents, ) -> Result<&mut Self, Error>

Remove the entry at rela_path, loading all trees on the path accordingly. It’s no error if the entry doesn’t exist, or if rela_path doesn’t lead to an existing entry at all.

Source

pub fn write(&mut self) -> Result<Id<'repo>, Error>

Write the entire in-memory state of all changed trees (and only changed trees) to the object database. Note that the returned object id can be the empty tree if everything was removed or if nothing was added to the tree.

The last call to out will be the changed root tree, whose object-id will also be returned. out is free to do any kind of additional validation, like to assure that all entries in the tree exist. We don’t assure that as there is no validation that inserted entries are valid object ids.

Future calls to upsert or similar will keep working on the last seen state of the just-written root-tree. If this is not desired, use set_root().

Before writing a tree, all of its entries (not only added ones), will be validated to assure they are correct. The objects pointed to by entries also have to exist already.

Source

pub fn get(&self, rela_path: impl ToComponents) -> Option<EntryRef<'repo, '_>>

Obtain the entry at rela_path or return None if none was found, or the tree wasn’t yet written to that point. The root tree is always available. Note that after writing only the root path remains, all other intermediate trees are removed. The entry can be anything that can be stored in a tree, but may have a null-id if it’s a newly inserted tree. Also, ids of trees might not be accurate as they may have been changed in memory.

Trait Implementations§

Source§

impl<'repo> Clone for Editor<'repo>

Source§

fn clone(&self) -> Editor<'repo>

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'repo> !Freeze for Editor<'repo>

§

impl<'repo> !RefUnwindSafe for Editor<'repo>

§

impl<'repo> !Send for Editor<'repo>

§

impl<'repo> !Sync for Editor<'repo>

§

impl<'repo> Unpin for Editor<'repo>

§

impl<'repo> !UnwindSafe for Editor<'repo>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T