Struct cpe::uri::Uri

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

A CPE 2.2 URI

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::uri::Uri;
 let uri = Uri::builder()
           .part("a")
           .vendor("foo%21")
           .validate()
           .unwrap();

 assert_eq!(format!("{}", uri), "cpe:/a:foo!:*:*:*:*:*".to_owned());
 assert_eq!(format!("{:#}", uri), "cpe:/a:foo%21:*:*:*:*:*".to_owned());

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

 use cpe::uri::Uri;
 let uri = Uri::builder()
           .part("a")
           .vendor("foo%21")
           .validate()
           .unwrap();

 assert_eq!(format!("{:0}", uri), "cpe:/a:foo!".to_owned());
 assert_eq!(format!("{:#0}", uri), "cpe:/a:foo%21".to_owned());

Implementations§

source§

impl<'a> Uri<'a>

source

pub fn new() -> Self

Create a new Uri with default values of ANY for each attribute.

source

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

Create a CpeBuilder struct to construct a new Wfn.

use cpe::uri::Uri;

let cpe: Uri = Uri::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 unpack a packed ~ delimited edition component if applicable.

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 to_owned(&self) -> OwnedUri

Create an Owned copy of this CPE URI.

source

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

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

source

pub fn parse(uri: &'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 Uri<'a>

source§

fn clone(&self) -> Uri<'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 Uri<'_>

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 Uri<'a>

source§

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

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

impl<'a> Default for Uri<'a>

source§

fn default() -> Uri<'a>

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

impl Display for Uri<'_>

source§

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

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

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

source§

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

Converts to this type from the input type.
source§

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

source§

fn from(cpe: &Uri<'_>) -> 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<'a> From<&Wfn<'a>> for Uri<'a>

source§

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

Converts to this type from the input type.
source§

impl From<Uri<'_>> for OwnedUri

source§

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

Converts to this type from the input type.
source§

impl From<Uri<'_>> for OwnedWfn

source§

fn from(cpe: Uri<'_>) -> 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<'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 Uri<'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 Uri<'a>

source§

fn eq(&self, other: &Uri<'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 Uri<'a>

source§

impl<'a> StructuralPartialEq for Uri<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Uri<'a>

§

impl<'a> RefUnwindSafe for Uri<'a>

§

impl<'a> Send for Uri<'a>

§

impl<'a> Sync for Uri<'a>

§

impl<'a> Unpin for Uri<'a>

§

impl<'a> UnwindSafe for Uri<'a>

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> 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> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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.