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
impl Replica
Sourcepub fn repo(&self) -> &Repository
pub fn repo(&self) -> &Repository
Access this Replica’s underlying repository.
Sourcepub fn get_all<E: Entity + EntityRead>(
&self,
) -> Result<impl Iterator<Item = Result<Result<E, Error<E>>, Error>>, Error>
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-bugdata (i.e., it was not initialized)
§The iterator will error
- If the repository does not contain
git-bugdata (i.e., it was not initialized) - If the
git-bugdata does not conform to the JSON schema.
Sourcepub fn get_all_with_query<E>(
&self,
query: &Query<Snapshot<E>>,
) -> Result<impl Iterator<Item = Result<Result<E, Error<E>>, Error>>, Error>
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-bugdata (i.e., it was not initialized)
§The iterator will error
- If the repository does not contain
git-bugdata (i.e., it was not initialized) - If the
git-bugdata does not conform to the JSON schema.
Sourcepub fn get_all_ids<E: Entity + EntityRead>(
&self,
) -> Result<impl Iterator<Item = Result<EntityId<E>, Error>>, Error>
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-bugdata (i.e., it was not initialized)
§Iterator Errors
- If one of the references could not be decoded.
Sourcepub fn get<E: Entity + EntityRead>(
&self,
id: EntityId<E>,
) -> Result<E, Error<E>>
pub fn get<E: Entity + EntityRead>( &self, id: EntityId<E>, ) -> Result<E, Error<E>>
§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.)