Struct cpe::wfn::Wfn

source ·
pub struct Wfn<'a> { /* private fields */ }
Expand description

A CPE 2.3 Well-Formed Name

Note: field access is limited to ensure values only contain semantically valid components. Fields can be accessed through the “getter” methods, or through the Cpe methods, although the former is preferred with a Cpe as opposed to an OwnedCpe.

Display is implemented to show the decoded contents by default, or to re-encode the components when # is used to specify an alternate.

 use cpe::wfn::Wfn;
 let wfn = Wfn::builder()
           .part("a")
           .vendor("foo\\!")
           .validate()
           .unwrap();

 assert_eq!(format!("{}", wfn), "wfn:[part=a,vendor=foo!,product=ANY,version=ANY,update=ANY,edition=ANY,language=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY]".to_owned());
 assert_eq!(format!("{:#}", wfn), "wfn:[part=a,vendor=foo\\!,product=ANY,version=ANY,update=ANY,edition=ANY,language=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY]".to_owned());

Additionally, the 0 for zero-padding integers can be used to omit default “ANY” fields.

 use cpe::wfn::Wfn;
 let wfn = Wfn::builder()
           .part("a")
           .vendor("foo\\!")
           .validate()
           .unwrap();

 assert_eq!(format!("{:0}", wfn), "wfn:[part=a,vendor=foo!]".to_owned());
 assert_eq!(format!("{:#0}", wfn), "wfn:[part=a,vendor=foo\\!]".to_owned());

Implementations§

source§

impl<'a> Wfn<'a>

source

pub fn new() -> Self

Create a default Wfn with all fields set to ANY.

source

pub fn builder() -> CpeBuilder<'a, Wfn<'a>>

Create a CpeBuilder struct to construct a new Wfn.

use cpe::wfn::Wfn;

let cpe: Wfn = Wfn::builder()
              .part("a")
              .vendor("rust")
              .product("cargo")
              .validate()
              .unwrap();

println!("{:?}", cpe);
source

pub fn set_part(&mut self, part: &'a str) -> Result<()>

Set the CPE type part, a, o, h, or *.

The provided string slice will be parsed to its semantic meaning.

source

pub fn set_vendor(&mut self, vendor: &'a str) -> Result<()>

Set the CPE vendor.

The provided string slice will be parsed to its semantic meaning.

source

pub fn set_product(&mut self, product: &'a str) -> Result<()>

Set the CPE product.

The provided string slice will be parsed to its semantic meaning.

source

pub fn set_version(&mut self, version: &'a str) -> Result<()>

Set the CPE product.

The provided string will be parsed to its semantic meaning.

source

pub fn set_update(&mut self, update: &'a str) -> Result<()>

Set the CPE update.

The provided string will be parsed to its semantic meaning.

source

pub fn set_edition(&mut self, edition: &'a str) -> Result<()>

Set the CPE edition.

The provided string will be parsed to its semantic meaning. Note that this funciton will not unpack a packed ~ delimited edition component.

source

pub fn set_language(&mut self, language: &'a str) -> Result<()>

Set the CPE language.

The provided string will be parsed to its semantic meaning. language must be a valid RFC-5646 language tag.

source

pub fn set_sw_edition(&mut self, sw_edition: &'a str) -> Result<()>

Set the CPE software edition.

The provided string will be parsed to its semantic meaning.

source

pub fn set_target_sw(&mut self, target_sw: &'a str) -> Result<()>

Set the CPE target software.

The provided string will be parsed to its semantic meaning.

source

pub fn set_target_hw(&mut self, target_hw: &'a str) -> Result<()>

Set the CPE target hardware.

The provided string will be parsed to its semantic meaning.

source

pub fn set_other(&mut self, other: &'a str) -> Result<()>

Set the CPE “other” value.

The provided string will be parsed to its semantic meaning.

source

pub fn to_owned(&self) -> OwnedWfn

Create an Owned copy of this CPE WFN.

source

pub fn as_uri(&self) -> Uri<'a>

Create a Uri, perserving lifetimes of the original input. Note that strings may be cloned if the input was decoded.

source

pub fn parse(value: &'a str) -> Result<Self>

Parse a CPE URI string.

This function will decode percent encodings and special characters to their semantic meaning.

Trait Implementations§

source§

impl<'a> Clone for Wfn<'a>

source§

fn clone(&self) -> Wfn<'a>

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 Cpe for Wfn<'_>

source§

fn part(&self) -> CpeType

source§

fn vendor(&self) -> Component<'_>

source§

fn product(&self) -> Component<'_>

source§

fn version(&self) -> Component<'_>

source§

fn update(&self) -> Component<'_>

source§

fn edition(&self) -> Component<'_>

source§

fn language(&self) -> &Language

source§

fn sw_edition(&self) -> Component<'_>

source§

fn target_sw(&self) -> Component<'_>

source§

fn target_hw(&self) -> Component<'_>

source§

fn other(&self) -> Component<'_>

source§

impl<'a> Debug for Wfn<'a>

source§

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

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

impl<'a> Default for Wfn<'a>

source§

fn default() -> Wfn<'a>

Returns the “default value” for a type. Read more
source§

impl Display for Wfn<'_>

source§

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

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

impl<'a> From<&Uri<'a>> for Wfn<'a>

source§

fn from(uri: &Uri<'a>) -> Self

Converts to this type from the input type.
source§

impl From<&Wfn<'_>> for OwnedUri

source§

fn from(cpe: &Wfn<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&Wfn<'_>> for OwnedWfn

source§

fn from(cpe: &Wfn<'_>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&Wfn<'a>> for Uri<'a>

source§

fn from(wfn: &Wfn<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Uri<'a>> for Wfn<'a>

source§

fn from(uri: Uri<'a>) -> Self

Converts to this type from the input type.
source§

impl From<Wfn<'_>> for OwnedUri

source§

fn from(cpe: Wfn<'_>) -> Self

Converts to this type from the input type.
source§

impl From<Wfn<'_>> for OwnedWfn

source§

fn from(cpe: Wfn<'_>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Wfn<'a>> for Uri<'a>

source§

fn from(wfn: Wfn<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> Hash for Wfn<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> PartialEq for Wfn<'a>

source§

fn eq(&self, other: &Wfn<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Wfn<'a>

source§

impl<'a> StructuralEq for Wfn<'a>

source§

impl<'a> StructuralPartialEq for Wfn<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Wfn<'a>

§

impl<'a> Send for Wfn<'a>

§

impl<'a> Sync for Wfn<'a>

§

impl<'a> Unpin for Wfn<'a>

§

impl<'a> UnwindSafe for Wfn<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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.