Struct PackageFileName

Source
pub struct PackageFileName {
    name: Name,
    version: Version,
    architecture: Architecture,
    compression: Option<CompressionAlgorithmFileExtension>,
}
Expand description

The full filename of a package.

A package filename tracks its Name, Version, Architecture and the optional CompressionAlgorithmFileExtension.

Fields§

§name: Name§version: Version§architecture: Architecture§compression: Option<CompressionAlgorithmFileExtension>

Implementations§

Source§

impl PackageFileName

Source

pub fn new( name: Name, version: Version, architecture: Architecture, compression: Option<CompressionAlgorithmFileExtension>, ) -> Result<Self, Error>

Creates a new PackageFileName.

§Errors

Returns an error if the provided version does not have the pkgrel component.

§Examples
use std::str::FromStr;

use alpm_types::PackageFileName;

assert_eq!(
    "example-1:1.0.0-1-x86_64.pkg.tar.zst",
    PackageFileName::new(
        "example".parse()?,
        "1:1.0.0-1".parse()?,
        "x86_64".parse()?,
        Some("zst".parse()?)
    )?
    .to_string()
);

// This fails because the provided Version does not have the pkgrel component.
assert!(
    PackageFileName::new(
        "example".parse()?,
        "1:1.0.0".parse()?,
        "x86_64".parse()?,
        Some("zst".parse()?)
    )
    .is_err()
);
Source

pub fn name(&self) -> &Name

Returns a reference to the Name.

§Examples
use std::str::FromStr;

use alpm_types::{Name, PackageFileName};

let file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;

assert_eq!(file_name.name(), &Name::new("example")?);
Source

pub fn version(&self) -> &Version

Returns a reference to the Version.

§Examples
use std::str::FromStr;

use alpm_types::{PackageFileName, Version};

let file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;

assert_eq!(file_name.version(), &Version::from_str("1:1.0.0-1")?);
Source

pub fn architecture(&self) -> Architecture

Returns the Architecture.

§Examples
use std::str::FromStr;

use alpm_types::{Architecture, PackageFileName};

let file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;

assert_eq!(file_name.architecture(), Architecture::X86_64);
Source

pub fn compression(&self) -> Option<CompressionAlgorithmFileExtension>

Returns the optional CompressionAlgorithmFileExtension.

§Examples
use std::str::FromStr;

use alpm_types::{CompressionAlgorithmFileExtension, PackageFileName};

let file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;

assert_eq!(
    file_name.compression(),
    Some(CompressionAlgorithmFileExtension::Zstd)
);
Source

pub fn to_path_buf(&self) -> PathBuf

Returns the PackageFileName as PathBuf.

§Examples
use std::{path::PathBuf, str::FromStr};

use alpm_types::PackageFileName;

let file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;

assert_eq!(
    file_name.to_path_buf(),
    PathBuf::from("example-1:1.0.0-1-x86_64.pkg.tar.zst")
);
Source

pub fn set_compression( &mut self, compression: Option<CompressionAlgorithmFileExtension>, )

Sets the compression of the PackageFileName.

§Examples
use std::str::FromStr;

use alpm_types::{CompressionAlgorithmFileExtension, PackageFileName};

// Create package file name with compression
let mut file_name = PackageFileName::new(
    "example".parse()?,
    "1:1.0.0-1".parse()?,
    "x86_64".parse()?,
    Some("zst".parse()?),
)?;
// Remove the compression
file_name.set_compression(None);

assert!(file_name.compression().is_none());

// Add other compression
file_name.set_compression(Some(CompressionAlgorithmFileExtension::Gzip));

assert!(
    file_name
        .compression()
        .is_some_and(|compression| compression == CompressionAlgorithmFileExtension::Gzip)
);
Source

pub fn parser(input: &mut &str) -> ModalResult<Self>

Recognizes a PackageFileName in a string slice.

Relies on [winnow] to parse input and recognize the Name, Version, Architecture and CompressionAlgorithmFileExtension components.

§Errors

Returns an error if

§Examples
use alpm_types::PackageFileName;
use winnow::Parser;

let filename = "example-package-1:1.0.0-1-x86_64.pkg.tar.zst";
assert_eq!(
    filename,
    PackageFileName::parser.parse(filename)?.to_string()
);

Trait Implementations§

Source§

impl Clone for PackageFileName

Source§

fn clone(&self) -> PackageFileName

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PackageFileName

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PackageFileName

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PackageFileName

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<PackageFileName> for String

Source§

fn from(value: PackageFileName) -> Self

Creates a String from a PackageFileName.

Source§

impl FromStr for PackageFileName

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Creates a PackageFileName from a string slice.

Delegates to PackageFileName::parser.

§Errors

Returns an error if PackageFileName::parser fails.

§Examples
use std::str::FromStr;

use alpm_types::PackageFileName;

let filename = "example-package-1:1.0.0-1-x86_64.pkg.tar.zst";
assert_eq!(filename, PackageFileName::from_str(filename)?.to_string());
Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

impl PartialEq for PackageFileName

Source§

fn eq(&self, other: &PackageFileName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PackageFileName

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&Path> for PackageFileName

Source§

fn try_from(value: &Path) -> Result<Self, Self::Error>

Creates a PackageFileName from a Path reference.

The file name in value is extracted and, if valid is turned into a string slice. The creation of the PackageFileName is delegated to PackageFileName::parser.

§Errors

Returns an error if

  • value does not contain a valid file name,
  • value can not be turned into a string slice,
  • or PackageFileName::parser fails.
§Examples
use std::path::PathBuf;

use alpm_types::PackageFileName;

let filename = PathBuf::from("../example-package-1:1.0.0-1-x86_64.pkg.tar.zst");
assert_eq!(
    filename,
    PathBuf::from("..").join(PackageFileName::try_from(filename.as_path())?.to_path_buf()),
);
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<String> for PackageFileName

Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Creates a PackageFileName from a String.

Delegates to PackageFileName::parser.

§Errors

Returns an error if PackageFileName::parser fails.

§Examples
use std::str::FromStr;

use alpm_types::PackageFileName;

let filename = "example-package-1:1.0.0-1-x86_64.pkg.tar.zst".to_string();
assert_eq!(
    filename.clone(),
    PackageFileName::try_from(filename)?.to_string()
);
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl Eq for PackageFileName

Source§

impl StructuralPartialEq for PackageFileName

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T