Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
chore: impl From for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
saenai255 committed Sep 6, 2022
1 parent 817e873 commit 7668b2a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/model/pacbuild.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//!

use chrono::NaiveDateTime as DateTime;
use serde_derive::{Deserialize, Serialize};

Expand Down Expand Up @@ -31,7 +33,7 @@ pub struct PacBuild {
/// ```
pub type Version = String;

/// Represents a `PacBuild` or Apt package name.
/// Represents a [`PacBuild`] or Apt package name.
/// # Examples
///
/// ```
Expand Down
36 changes: 18 additions & 18 deletions src/store/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@ pub type StoreResult<T> = Result<T, StoreError>;

/// Abstraction over the caching implementation
pub trait Base: Debug {
/// Removes `PacBuild` by name that belongs to the given repository.
/// Removes [`PacBuild`] by name that belongs to the given repository.
///
/// # Errors
/// * `StoreError::RepositoryNotFound`
/// * `StoreError::PacBuildNotFound`
/// * [`StoreError::RepositoryNotFound`]
/// * [`StoreError::PacBuildNotFound`]
fn remove_pacbuild(&mut self, name: &str, repository_url: &str) -> StoreResult<()>;

/// Adds `PacBuild` to the given repository.
/// Adds [`PacBuild`] to the given repository.
///
/// # Errors
/// * `StoreError::RepositoryConflict`
/// * `StoreError::PacBuildConflict`
/// * [`StoreError::RepositoryConflict`]
/// * [`StoreError::PacBuildConflict`]
fn add_pacbuild(&mut self, pacbuild: PacBuild, repository_url: &str) -> StoreResult<()>;

/// Updates `PacBuild` that belongs to the given repository.
/// Updates [`PacBuild`] that belongs to the given repository.
///
/// # Errors
/// * `StoreError::RepositoryNotFound`
/// * `StoreError::PacBuildNotFound`
/// * [`StoreError::RepositoryNotFound`]
/// * [`StoreError::PacBuildNotFound`]
fn update_pacbuild(&mut self, pacbuild: PacBuild, repository_url: &str) -> StoreResult<()>;

/// Removes all `PacBuild` by name that belongs to the given repository.
/// Removes all [`PacBuild`] by name that belongs to the given repository.
///
/// # Errors
/// * `StoreError::Aggregate`
/// * [`StoreError::Aggregate`]
fn remove_all_pacbuilds(&mut self, name: &[&str], repository_url: &str) -> StoreResult<()>;

/// Adds all `PacBuild` to the given repository.
/// Adds all [`PacBuild`] to the given repository.
///
/// # Errors
/// * `StoreError::Aggregate`
/// * [`StoreError::Aggregate`]
fn add_all_pacbuilds(
&mut self,
pacbuilds: Vec<PacBuild>,
repository_url: &str,
) -> StoreResult<()>;

/// Updates all `PacBuild` that belongs to the given repository.
/// Updates all [`PacBuild`] that belongs to the given repository.
///
/// # Errors
/// * `StoreError::Aggregate`
/// * [`StoreError::Aggregate`]
fn update_all_pacbuilds(
&mut self,
pacbuilds: Vec<PacBuild>,
Expand All @@ -61,19 +61,19 @@ pub trait Base: Debug {
/// Removes [Repository] by url.
///
/// # Errors
/// * `StoreError::RepositoryNotFound`
/// * [`StoreError::RepositoryNotFound`]
fn remove_repository(&mut self, repository_url: &str) -> StoreResult<()>;

/// Adds `Repository`.
///
/// # Errors
/// * `StoreError::RepositoryConflict`
/// * [`StoreError::RepositoryConflict`]
fn add_repository(&mut self, repository: Repository) -> StoreResult<()>;

/// Updates [Repository].
///
/// # Errors
/// * `StoreError::RepositoryConflict`
/// * [`StoreError::RepositoryConflict`]
fn update_repository(&mut self, repository: Repository) -> StoreResult<()>;

/// Find first by name in the given repository
Expand Down
10 changes: 10 additions & 0 deletions src/store/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub enum InstallState {
None,
}

impl From<&crate::model::InstallState> for InstallState {
fn from(other: &crate::model::InstallState) -> Self {
InstallState::from_model_install_state(other)
}
}

impl InstallState {
pub fn from_model_install_state(other: &crate::model::InstallState) -> InstallState {
match other {
Expand All @@ -28,6 +34,10 @@ pub enum Kind {
GitRelease,
}

impl From<&crate::model::Kind> for Kind {
fn from(other: &crate::model::Kind) -> Self { Kind::from_model_kind(other) }
}

impl Kind {
pub fn from_model_kind(other: &crate::model::Kind) -> Kind {
match other {
Expand Down
5 changes: 2 additions & 3 deletions src/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,14 @@ impl Base for FileSystemStore {
.flat_map(|(_, pkgs)| pkgs)
.filter(|it| {
if let Some(kind_filter) = &kind {
*kind_filter == Kind::from_model_kind(&it.kind)
*kind_filter == (&it.kind).into()
} else {
true
}
})
.filter(|it| {
if let Some(install_state_filter) = &install_state {
*install_state_filter
== InstallState::from_model_install_state(&it.install_state)
*install_state_filter == (&it.install_state).into()
} else {
true
}
Expand Down

0 comments on commit 7668b2a

Please sign in to comment.