Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a new structure to represent package requirements #99

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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