Replica

Struct Replica 

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

A persistent storage for git-bug data on disk.

For now this is always a git repository.

Implementations§

Source§

impl Replica

Source

pub fn from_path(path: impl Into<PathBuf>) -> Result<Self, Error>

Open a Replica from a path to a git repository.

This path is extended with .git, if the repository is non-bare and the path points into it.

§Errors

If opening the repository fails.

Source

pub fn repo(&self) -> &Repository

Access this Replica’s underlying repository.

Source

pub fn db(&self) -> &Database

Access this Replica’s cache database.

Source

pub fn get_all<E: Entity + EntityRead>( &self, ) -> Result<impl Iterator<Item = Result<Result<E, Error<E>>, Error>>, Error>

Return an iterator over all the Entities E stored in this replica.

§Errors
  • If the repository does not contain git-bug data (i.e., it was not initialized)
§The iterator will error
  • If the repository does not contain git-bug data (i.e., it was not initialized)
  • If the git-bug data does not conform to the JSON schema.
Source

pub fn get_all_with_query<E>( &self, query: &Query<Snapshot<E>>, ) -> Result<impl Iterator<Item = Result<Result<E, Error<E>>, Error>>, Error>

Return an iterator over all the Entities E stored in this replica that match the query.

§Note

This calls Query::matches under the hood, and as such will produce snapshots for all Entities. In the future, this might be improved.

§Errors
  • If the repository does not contain git-bug data (i.e., it was not initialized)
§The iterator will error
  • If the repository does not contain git-bug data (i.e., it was not initialized)
  • If the git-bug data does not conform to the JSON schema.
Source

pub fn get_all_ids<E: Entity + EntityRead>( &self, ) -> Result<impl Iterator<Item = Result<EntityId<E>, Error>>, Error>

Return an iterator over all the EntityIds for the Entity E stored in this replica.

§Note

This function does not have a _with_query variant, as such a variant would have to call Query::matches under the hood, and as such will create snapshots for all Entities.

If you only need to Ids of matched Entities use the following instead:

use git_bug::{
    entities::issue::Issue,
    query::{ParseMode, Query},
    replica::{
        Replica,
        entity::{Entity, snapshot::Snapshot},
    },
};

let query: Query<Snapshot<Issue>> =
    Query::from_continuous_str(replica, "title:test", ParseMode::Strict)?;

for maybe_entity in replica.get_all_with_query(&query)? {
    let entity = maybe_entity??;
    let id = entity.id();
    println!("Found id: {id}");
}
§Errors
  • If the repository does not contain git-bug data (i.e., it was not initialized)
§Iterator Errors
  • If one of the references could not be decoded.
Source

pub fn get<E: Entity + EntityRead>( &self, id: EntityId<E>, ) -> Result<E, Error<E>>

Get an Entity by EntityId.

§Note

This is useful if you have already obtained an EntityId via functions like Replica::get_all_ids. If you only have an Id, use the Replica::get_by_id function instead.

§Errors

If the entity read operation (i.e., EntityRead::read fails.)

Source

pub fn get_by_id<E: Entity + EntityRead>( &self, id: Id, ) -> Result<Result<E, Error<E>>, Error>

Get an Entity by it’s Id.

§Note

This will search for the Id first and as such should not be used if you have already obtained an EntityId. If your Id is not found it will return an appropriate error.

§Errors

If the entity read operation (i.e., EntityRead::read fails.)

Source

pub fn contains<E: Entity + EntityRead>(&self) -> Result<bool, Error>

Convenience function, that checks whether git-bug data for an Entity has been stored in this replica.

§Errors
  • If iterating over the git references fails (e.g., because the underlying repository was never initialized.)

Trait Implementations§

Source§

impl Debug for Replica

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Replica

§

impl !RefUnwindSafe for Replica

§

impl !Send for Replica

§

impl !Sync for Replica

§

impl Unpin for Replica

§

impl !UnwindSafe for Replica

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> 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, 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,