pub struct OptionalDependency {
package_relation: PackageRelation,
description: Option<String>,
}Expand description
An optional dependency for a package.
This type is used for representing dependencies that are not essential for base functionality of a package, but may be necessary to make use of certain features of a package.
An OptionalDependency consists of a package relation and an optional description separated
by a colon (:).
- The package relation component must be a valid
PackageRelation. - If a description is provided it must be at least one character long.
Refer to alpm-package-relation of type optional dependency for details on the format.
§Examples
use std::str::FromStr;
use alpm_types::{Name, OptionalDependency};
// Create OptionalDependency from &str
let opt_depend = OptionalDependency::from_str("example: this is an example dependency")?;
// Get the name
assert_eq!("example", opt_depend.name().as_ref());
// Get the description
assert_eq!(
Some("this is an example dependency"),
opt_depend.description().as_deref()
);
// Format as String
assert_eq!(
"example: this is an example dependency",
format!("{opt_depend}")
);Fields§
§package_relation: PackageRelation§description: Option<String>Implementations§
Source§impl OptionalDependency
impl OptionalDependency
Sourcepub fn new(
package_relation: PackageRelation,
description: Option<String>,
) -> OptionalDependency
pub fn new( package_relation: PackageRelation, description: Option<String>, ) -> OptionalDependency
Create a new OptionalDependency in a Result
Sourcepub fn version_requirement(&self) -> &Option<VersionRequirement>
pub fn version_requirement(&self) -> &Option<VersionRequirement>
Return the version requirement of the optional dependency
Sourcepub fn description(&self) -> &Option<String>
pub fn description(&self) -> &Option<String>
Return the description for the optional dependency, if it exists
Sourcepub fn package_relation(&self) -> &PackageRelation
pub fn package_relation(&self) -> &PackageRelation
Returns a reference to the tracked PackageRelation.
Trait Implementations§
Source§impl AlpmParser for OptionalDependency
impl AlpmParser for OptionalDependency
Source§fn parser(input: &mut &str) -> ModalResult<Self>
fn parser(input: &mut &str) -> ModalResult<Self>
Recognizes an OptionalDependency in a string slice.
This format is inherently flawed, as the : delimiter may exist in two different, optional
places.
- After the optional epoch
- Before the optional description
The : delimiter may also appear inside the description, although that isn’t an issue
during parsing.
why>=1:17.0.1-5: my dependency
is>=1:17.0.1-5
it>=17.0.1-5: my other dependency :::::
this: 1:17.0.1-5 my other dependency
way>1: 17.0.1-5 ambiguous.Due to this, the parser disambiguates the two cases as follows:
- A
:directly followed by a non-whitespace character is considered an epoch delimiter. - A
:followed by whitespace starts a description.
As such, ambiguous input like example>=1:foo bar is treated as containing an epoch and
rejected, as foo bar is not a valid version.
Input like example>=1: 3.2.1-5 foo bar is successfully parsed with the version being 1
and the description being 3.2.1-5 foo bar.
§Errors
Returns an error if input is not a valid alpm-package-relation of type optional
dependency.
Source§impl Clone for OptionalDependency
impl Clone for OptionalDependency
Source§fn clone(&self) -> OptionalDependency
fn clone(&self) -> OptionalDependency
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OptionalDependency
impl Debug for OptionalDependency
Source§impl<'de> Deserialize<'de> for OptionalDependency
impl<'de> Deserialize<'de> for OptionalDependency
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for OptionalDependency
impl Display for OptionalDependency
Source§impl FromStr for OptionalDependency
impl FromStr for OptionalDependency
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new OptionalDependency from a string slice.
Delegates to OptionalDependency::parser.
§Errors
Returns an error if OptionalDependency::parser fails.
Source§impl PartialEq for OptionalDependency
impl PartialEq for OptionalDependency
Source§fn eq(&self, other: &OptionalDependency) -> bool
fn eq(&self, other: &OptionalDependency) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for OptionalDependency
impl Serialize for OptionalDependency
impl Eq for OptionalDependency
impl StructuralPartialEq for OptionalDependency
Auto Trait Implementations§
impl Freeze for OptionalDependency
impl RefUnwindSafe for OptionalDependency
impl Send for OptionalDependency
impl Sync for OptionalDependency
impl Unpin for OptionalDependency
impl UnsafeUnpin for OptionalDependency
impl UnwindSafe for OptionalDependency
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<U> ParserUntil for Uwhere
U: AlpmParser,
impl<U> ParserUntil for Uwhere
U: AlpmParser,
Source§fn parser_until<'a, P>(
delimiter: P,
) -> impl Parser<&'a str, U, ErrMode<ContextError>>
fn parser_until<'a, P>( delimiter: P, ) -> impl Parser<&'a str, U, ErrMode<ContextError>>
Returns a [Parser] that parses Self until the given delimiter parser
matches.
§Note
Does not consume the delimiter.
Source§fn parser_until_eof(input: &mut &str) -> Result<Self, ErrMode<ContextError>>
fn parser_until_eof(input: &mut &str) -> Result<Self, ErrMode<ContextError>>
Source§impl<U> ParserUntilInclusive for Uwhere
U: ParserUntil,
impl<U> ParserUntilInclusive for Uwhere
U: ParserUntil,
Source§fn parser_until_inclusive<'a, P>(
delimiter: P,
) -> impl Parser<&'a str, U, ErrMode<ContextError>>
fn parser_until_inclusive<'a, P>( delimiter: P, ) -> impl Parser<&'a str, U, ErrMode<ContextError>>
Returns a [Parser] that parses the whole input and consumes the given delimiter parser.
Delegates to ParserUntil::parser_until and consumes the delimiter.