Skip to main content

LinkValue

Struct LinkValue 

Source
pub struct LinkValue<'a> { /* private fields */ }
Expand description

One link value: a target and its parameters.

§Examples

use parse_net::{parse_link, Limits};

let v = parse_link(b"<https://x.test/>; rel=canonical", &Limits::DEFAULT)?.iter().next().expect("one link");
assert_eq!(v.target(), b"https://x.test/");
assert!(v.has_rel("canonical"));

Implementations§

Source§

impl<'a> LinkValue<'a>

Source

pub const fn target(&self) -> &'a [u8] ⓘ

The URI-reference between < and >, as sent (not resolved).

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</docs/%7Euser>", &Limits::DEFAULT)?.iter().next().expect("one link");
assert_eq!(v.target(), b"/docs/%7Euser");
Source

pub const fn params(&self) -> LinkParams<'a>

The parameters, in order.

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a>; rel=next; crossorigin", &Limits::DEFAULT)?.iter().next().expect("one link");
let p = v.params();
assert_eq!(p.len(), 2);
assert!(p.iter().any(|(n, w)| n == b"crossorigin" && w.is_none()));
Source

pub fn rel(&self) -> Option<Word<'a>>

The first rel value; later rel parameters are ignored (RFC 8288 section 3.3).

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a>; rel=\"next last\"; rel=prev", &Limits::DEFAULT)?.iter().next().expect("one link");
assert!(v.rel().is_some_and(|w| w.eq_bytes(b"next last")));
Source

pub fn rels(&self) -> RelIter<'a> ⓘ

The relation types of the first rel, split on spaces. A relation type is a token or a URI, so it never needs a quoted pair; one that has one is yielded as sent.

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a>; rel=\"next last\"", &Limits::DEFAULT)?.iter().next().expect("one link");
let rels: Vec<&[u8]> = v.rels().collect();
assert_eq!(rels, [&b"next"[..], b"last"]);
Source

pub fn has_rel(&self, rel: &str) -> bool

Whether the first rel lists rel (ASCII case-insensitive).

§Examples
use parse_net::{parse_link, Limits};

let l = parse_link(b"</style.css>; rel=\"Preload stylesheet\"", &Limits::DEFAULT)?;
let v = l.iter().next().expect("one link");
assert!(v.has_rel("preload") && v.has_rel("STYLESHEET") && !v.has_rel("style"));
Source

pub fn anchor(&self) -> Option<Word<'a>>

The first anchor.

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a>; rel=next; anchor=\"#top\"", &Limits::DEFAULT)?.iter().next().expect("one link");
assert!(v.anchor().is_some_and(|w| w.eq_bytes(b"#top")));
Source

pub fn hreflang(&self) -> HreflangIter<'a> ⓘ

Every hreflang, in order (the one parameter RFC 8288 lets repeat).

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a>; rel=alternate; hreflang=en; hreflang=de", &Limits::DEFAULT)?.iter().next().expect("one link");
let langs: Vec<_> = v.hreflang().map(|w| w.as_str()).collect();
assert_eq!(langs, [Some("en"), Some("de")]);
Source

pub fn title(&self) -> Option<Filename<'a>>

The title: the first title* (RFC 8187, decoded like filename*) when present, else the first title.

§Examples
use parse_net::{parse_link, Limits};

let l = parse_link(b"<a>; title=\"EUR\"; title*=UTF-8''%E2%82%AC", &Limits::DEFAULT)?;
let mut buf = [0u8; 8];
let t = l.iter().next().and_then(|v| v.title()).expect("a title");
assert_eq!(t.decode_into(&mut buf)?, "\u{20ac}");
Source

pub fn media(&self) -> Option<Word<'a>>

The first media.

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</s.css>; rel=stylesheet; media=\"screen\"", &Limits::DEFAULT)?.iter().next().expect("one link");
assert!(v.media().is_some_and(|w| w.eq_bytes(b"screen")));
Source

pub fn type_(&self) -> Option<Word<'a>>

The first type.

§Examples
use parse_net::{parse_link, Limits};

let v = parse_link(b"</a.json>; rel=alternate; type=\"application/json\"", &Limits::DEFAULT)?.iter().next().expect("one link");
assert!(v.type_().is_some_and(|w| w.eq_bytes(b"application/json")));

Trait Implementations§

Source§

impl<'a> Clone for LinkValue<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for LinkValue<'a>

Source§

impl<'a> Debug for LinkValue<'a>

Source§

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

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

impl<'a> Eq for LinkValue<'a>

Source§

impl<'a> Hash for LinkValue<'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 LinkValue<'a>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for LinkValue<'a>

Auto Trait Implementations§

§

impl<'a> Forget for LinkValue<'a>

§

impl<'a> Freeze for LinkValue<'a>

§

impl<'a> RefUnwindSafe for LinkValue<'a>

§

impl<'a> Send for LinkValue<'a>

§

impl<'a> Sync for LinkValue<'a>

§

impl<'a> Unpin for LinkValue<'a>

§

impl<'a> UnsafeUnpin for LinkValue<'a>

§

impl<'a> UnwindSafe for LinkValue<'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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.