Skip to content

Commit

Permalink
Introduce a new structure to represent package requirements (#99)
Browse files Browse the repository at this point in the history
With that change, the previous PackageRequirement structure was renamed
to SoftPackageRequirement, and the new structure took its original name.
  • Loading branch information
doom authored and Arignir committed Aug 19, 2019
1 parent 1f2b3f3 commit 29840c1
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 50 deletions.
4 changes: 2 additions & 2 deletions libnest/src/cache/available/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use failure::{Error, ResultExt};
use serde_json;

use crate::lock_file::LockFileOwnership;
use crate::package::{PackageManifest, PackageRequirement};
use crate::package::{PackageManifest, SoftPackageRequirement};
use crate::repository::Repository;

/// Structure representing the cache of available packages
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'cache_root, 'lock_file> AvailablePackages<'cache_root, 'lock_file> {
#[inline]
pub fn query<'pkg_req>(
&self,
requirement: &'pkg_req PackageRequirement,
requirement: &'pkg_req SoftPackageRequirement,
) -> AvailablePackagesCacheQuery<'cache_root, 'pkg_req> {
AvailablePackagesCacheQuery::from(&self.cache_root, requirement)
}
Expand Down
8 changes: 4 additions & 4 deletions libnest/src/cache/available/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::path::Path;
use failure::{Error, ResultExt};

use crate::package::{
CategoryName, Manifest, PackageFullName, PackageID, PackageManifest, PackageRequirement,
RepositoryName,
CategoryName, Manifest, PackageFullName, PackageID, PackageManifest, RepositoryName,
SoftPackageRequirement,
};

/// The result of a query to the packages cache
Expand Down Expand Up @@ -76,15 +76,15 @@ pub enum AvailablePackagesCacheQueryStrategy {
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct AvailablePackagesCacheQuery<'a, 'b> {
cache_root: &'a Path,
requirement: &'b PackageRequirement,
requirement: &'b SoftPackageRequirement,
strategy: AvailablePackagesCacheQueryStrategy,
}

impl<'a, 'b> AvailablePackagesCacheQuery<'a, 'b> {
#[inline]
pub(crate) fn from(
cache_root: &'a Path,
requirement: &'b PackageRequirement,
requirement: &'b SoftPackageRequirement,
) -> AvailablePackagesCacheQuery<'a, 'b> {
AvailablePackagesCacheQuery {
cache_root,
Expand Down
42 changes: 40 additions & 2 deletions libnest/src/package/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,51 @@ pub enum PackageShortNameParseErrorKind {

use_as_error!(PackageShortNameParseError, PackageShortNameParseErrorKind);

/// Type for errors related to the parsing of a [`PackageRequirement`]
/// Type for errors related to the parsing of a [`SoftPackageRequirement`]
#[derive(Debug)]
pub struct SoftPackageRequirementParseError {
inner: Context<SoftPackageRequirementParseErrorKind>,
}

/// Type describing a kind of error related to the parsing of a [`SoftPackageRequirement`]
#[derive(Clone, Eq, PartialEq, Hash, Debug, Fail)]
pub enum SoftPackageRequirementParseErrorKind {
/// The given string does not follow the format for package requirements
#[fail(
display = "\"{}\" doesn't follow the `repository::category/name#version` format",
_0
)]
InvalidFormat(String),

/// The name component of the package requirement has invalid characters
#[fail(display = "{}", _0)]
InvalidName(#[cause] PackageNameParseError),

/// The category component of the package requirement has invalid characters
#[fail(display = "{}", _0)]
InvalidCategory(#[cause] CategoryNameParseError),

/// The repository component of the package requirement has invalid characters
#[fail(display = "{}", _0)]
InvalidRepository(#[cause] RepositoryNameParseError),

/// The version component of the package requirement is not a valid version
#[fail(display = "invalid version syntax")]
InvalidVersion,
}

use_as_error!(
SoftPackageRequirementParseError,
SoftPackageRequirementParseErrorKind
);

/// Type for errors related to the parsing of a [`SoftPackageRequirement`]
#[derive(Debug)]
pub struct PackageRequirementParseError {
inner: Context<PackageRequirementParseErrorKind>,
}

/// Type describing a kind of error related to the parsing of a [`PackageRequirement`]
/// Type describing a kind of error related to the parsing of a [`SoftPackageRequirement`]
#[derive(Clone, Eq, PartialEq, Hash, Debug, Fail)]
pub enum PackageRequirementParseErrorKind {
/// The given string does not follow the format for package requirements
Expand Down
2 changes: 1 addition & 1 deletion libnest/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub use identification::{
pub use manifest::{Kind, Manifest, PackageManifest, VersionData};
pub use metadata::{License, Maintainer, Metadata, Tag, UpstreamURL};
pub use npf::{NPFExplorer, NPFFile};
pub use requirement::{HardPackageRequirement, PackageRequirement};
pub use requirement::{HardPackageRequirement, PackageRequirement, SoftPackageRequirement};

lazy_static::lazy_static! {
/// A regular expression to match and parse a package's string representation
Expand Down
Loading

0 comments on commit 29840c1

Please sign in to comment.