pub struct Hyperlink { /* private fields */ }Expand description
A declared OSC 8 hyperlink, as handed to a consumer.
Owned, not borrowed, and that is the point: the URI lives in a row’s side map, so
a &str into it would be tied to &Engine and a caller could not hold the link
across the next feed() — which is precisely what a hover handler does. Measured on
the alternative: reading a borrow costs 0.75 ns, but keeping it does not compile, so
the caller copies the string instead at 62.6 ns. Handing back this handle is 17.9 ns
— cheaper than the workaround it removes, on a call made once per hover.
Cloning is a refcount bump; the allocation is shared with every cell of the same OSC 8 open and released when the last row holding it dies (#628).
A struct rather than a bare Arc<str> for two reasons: it keeps Arc out of the
published signature, and OSC 8’s id= parameter (#635) lands here as a field without
changing the return type again. Same shape as alacritty’s Hyperlink, for the same
reasons (alacritty_terminal/src/term/cell.rs).
Link identity is deliberately not exposed yet. Two OSC 8 opens of an identical
URI are two links here, so uri() == uri() cannot answer “is this cell part of the
same link as that one?” — an Arc::ptr_eq accessor would. It is left out because no
consumer asks it today (nothing outside this crate’s tests calls link_at at all),
and unlike this type’s shape, adding a method later is not a breaking change. The
asymmetry decides it: shipping an accessor nobody uses is hard to undo, adding one
when a caller appears is free.
No #[non_exhaustive] (#844): nothing outside this crate has a reason to build one. No
public function accepts it — the engine hands it out — and there are zero out-of-crate literal
sites, so the attribute would bind nothing it does not already bind.
Implementations§
Source§impl Hyperlink
impl Hyperlink
Sourcepub fn uri(&self) -> &str
pub fn uri(&self) -> &str
The link target, exactly as the application declared it — never validated, never resolved. Whether it is a URL a consumer is willing to open is that consumer’s policy (ADR-0017), the same way colour resolution is.
One exception to “exactly”: a URI containing 14 or more unencoded ; arrives
cut short, because the parser this engine builds on passes at most 16 OSC fields.
The shorter URI is not marked as cut. A percent-encoded %3B is unaffected.