# UriRef

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/utilities/enum-uriref/

**enum** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
enum UriRef
```

A URI reference (RFC 3986, section 4.1): an absolute URL, or a reference
relative to a base URL.

Equality and hashing are the ones of `url::Url` for an absolute
reference, with the fragment (decision O5 of
docs/idiomatic-rust-signatures.md: `resm:A.B#Name` is not `resm:A.B`), and
the text for a relative one; an absolute reference never equals a relative
one. [`Uri`](/docs/0.5.0/api/ferroui-base/utilities/struct-uri/) compares absolute URIs without their fragment, as .NET does: a
map that needs that rule keys by `without_fragment`
explicitly.

The text of a URL is the one of the URL standard: the special schemes
(`http`, `https`, `file`, ...) are normalised (`http://host` is
`http://host/`, default ports and dot segments go, characters outside the
allowed set are percent-encoded); the schemes of the framework (`ferres://`,
`fonts:`, `resm:`) and `file://` URLs keep their text.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L32)

## Members

- [`Absolute`](#variant-absolute)
- [`Relative`](#variant-relative)
- [`parse`](#function-parse)
- [`parse_absolute`](#function-parse_absolute)
- [`resolve`](#function-resolve)
- [`as_url`](#function-as_url)
- [`is_relative`](#function-is_relative)
- [`without_fragment`](#function-without_fragment)

<a id="variant-absolute"></a>

### Absolute

```rust
Absolute(url::Url)
```

An absolute URL.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L34)

<a id="variant-relative"></a>

### Relative

```rust
Relative(Box<str>)
```

A reference relative to a base URL, as written.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L36)

<a id="function-parse"></a>

### parse

```rust
fn parse(text: &str) -> Result<Self, url::ParseError>
```

Parses a URI reference with the rule of markup (`FerroUriTypeConverter`
and the URI literals of the compiler): a text that starts with `/` is
relative, never a file path; a text with a scheme is absolute, where a
scheme has two characters or more (`C:` is a drive letter, as for
`Uri`); any other text is relative.

The URL of an absolute reference is the canonical text of the `Uri`
of the text (the scheme and the authority in lower case) parsed with
`url::Url::parse`, so that for every text `Uri` accepts,
`UriRef::parse(text)` is the reference of
`Uri::new(text, UriKind::RelativeOrAbsolute)` (`TryFrom<&Uri> for UriRef`).
A text the URL parser rejects (`http://host:99999/`) is its error.
Unlike `Uri`, a scheme with nothing after it (`foo:`) is a URL.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L53)

<a id="function-parse_absolute"></a>

### parse_absolute

```rust
fn parse_absolute(text: &str) -> Result<url::Url, UriToUrlError>
```

Parses an absolute URL with the rule of `parse` (the
scheme and the authority in lower case, as the canonical text of
`Uri` writes them): the base URI of a document (C#
`new Uri(text, UriKind.Absolute)`). Two spellings of one document
(`FERRES://App/Main.xaml`, `ferres://app/Main.xaml`) are one URL, as
they are one `Uri`; `url::Url::parse` keeps the case of the host of a
scheme that is not special.

A relative reference is `UriToUrlError::Relative`, and a text the
URL parser rejects `UriToUrlError::Invalid`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L70)

<a id="function-resolve"></a>

### resolve

```rust
fn resolve(self: &Self, base: &url::Url) -> Result<url::Url, url::ParseError>
```

Resolves the reference against the absolute `base` (C# `new Uri(Uri, Uri)`,
`Uri::combine` of the port): an absolute reference is itself, and a
relative one is resolved with `url::Url::join`.

For the references markup writes (a relative path, a path that starts
with `/`, dot segments, a query, a fragment) against a base of the
framework (`ferres://`, `fonts:`, `resm:`, `file://`), the URL is the one
of `Uri::combine`, converted to a URL. `Url::join` cannot resolve
against a URL whose path is opaque (`fonts:SystemFonts`,
`resm:Fonts.Assets?assembly=App`); there the reference is resolved as
`Uri::combine` resolves it (`fonts:Other`). A first segment with a colon
and no scheme (`C:x`) stays a path, as for `Uri`.

Where the URL standard differs from `Uri::combine`, the URL follows the
standard (and RFC 3986, as .NET does):

- a reference that is only a fragment (`#Name`), or empty, keeps the
  query of the base, which `Uri::combine` drops;
- a reference that starts with `//` names an authority (`//host/path`),
  where `Uri::combine` reads a path of the authority of the base;
- empty segments (`a//b`) stay, where `Uri::combine` removes them;
- a `file:` URL of a drive (`file:///C:/dir/`) keeps its drive for a
  path that starts with `/` and for `..` above the drive, where
  `Uri::combine` goes to the root (`file:///Styles/Base.xaml`);
- the special schemes are normalised as the text of every URL is (the
  type documentation), and the host of another scheme has the case of
  `base` (`UriRef::parse` and the conversions from `Uri` write it in
  lower case, as `Uri` does).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L105)

<a id="function-as_url"></a>

### as_url

```rust
fn as_url(self: &Self) -> Option<&url::Url>
```

The URL of an absolute reference; `None` for a relative one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L128)

<a id="function-is_relative"></a>

### is_relative

```rust
fn is_relative(self: &Self) -> bool
```

Whether the reference is relative (C# `!IsAbsoluteUri`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L136)

<a id="function-without_fragment"></a>

### without_fragment

```rust
fn without_fragment(self: &Self) -> UriRef
```

The reference without its fragment (`resm:A.B#Name` is `resm:A.B`): the
key of a map that compares URIs as .NET's `Uri` does (decision O5 of
docs/idiomatic-rust-signatures.md). `Uri` ignores the fragment of an
absolute URI only and compares a relative one by its whole text, so a
key that follows `Uri` exactly takes this of the absolute references.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/uri_ref.rs#L145)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Eq`
- `Hash`
- `Display`
- `FromStr`
- `From<Url>`
- `TryFrom<UriRef>`
- `TryFrom<&UriRef>`
- `TryFrom<&Uri>`
- `From<&UriRef>`
- `From<UriRef>`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
