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 parser(input: &mut &str) -> ModalResult<Self>
pub fn parser(input: &mut &str) -> ModalResult<Self>
Recognizes an OptionalDependency
in a string slice.
Consumes all of its input.
§Errors
Returns an error if input
is not a valid alpm-package-relation of type optional
dependency.
Trait Implementations§
Source§impl Clone for OptionalDependency
impl Clone for OptionalDependency
Source§fn clone(&self) -> OptionalDependency
fn clone(&self) -> OptionalDependency
1.0.0 · 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.