Search results

There are no results.

std.uri.Path

type pub inline Path

The path of a URI.

Static methods

new

Show source code
Hide source code
fn pub static new(path: String) -> Option[Self] {
  match parse(path, start: 0, standalone: true) {
    case Ok((Some(val), _)) -> Option.Some(val)
    case Ok(_) -> Option.Some(Path(''))
    case _ -> Option.None
  }
}
fn pub static new(path: String) -> Option[Path]

Returns a Path created from the given String.

If the supplied path string is invalid, an Option.None is returned.

Normalization

If the path argument is an absolute path containing . or .. segments, the path is normalized such that e.g. /foo/../bar is turned into /bar.

Examples

import std.uri (Path)

Path.new('/hello/world') # => Option.Some(Path('/hello/world'))
Path.new('foo?bar')      # => Option.None

Instance methods

!=

Show source code
Hide source code
fn pub !=(other: ref Self) -> Bool {
  (self == other).false?
}
fn pub !=(other: ref Self) -> Bool

Returns true if self and the given object are not equal to each other.

==

Show source code
Hide source code
fn pub ==(other: ref Path) -> Bool {
  decoded == other.decoded
}
fn pub ==(other: ref Path) -> Bool

Returns true if self and other are equal.

The comparison is performed after performing percent decoding, such that hello%20world and hello world are considered to be equal to each other.

absolute?

Show source code
Hide source code
fn pub inline absolute? -> Bool {
  @value.starts_with?('/')
}
fn pub inline absolute? -> Bool

Returns true if self is an absolute path.

Examples

import std.uri (Path)

Path.new('/hello').get.absolute? # => true
Path.new('hello').get.absolute? # => false

components

Show source code
Hide source code
fn pub components -> PathComponents {
  PathComponents(path: @value, index: 0)
}
fn pub components -> PathComponents

Returns an iterator over the components in self.

Percent decoding

Components containing percent-encoded sequences are decoded into a PathComponent.Owned after splitting the components.

Examples

import std.uri (Uri)

let uri = Uri.parse('https://example.com/foo/bar').or_panic
let iter = uri.path.as_ref.get.components

iter.next.or_panic.to_string # => '/'
iter.next.or_panic.to_string # => 'foo'

empty?

Show source code
Hide source code
fn pub inline empty? -> Bool {
  size == 0
}
fn pub inline empty? -> Bool

Returns true if self is empty.

Examples

import std.uri (Path)

Path.new('').get.empty? # => true
Path.new('foo').get.empty? # => false

fmt

Show source code
Hide source code
fn pub fmt(formatter: mut Formatter) {
  formatter.object('Path').field('value', @value).finish
}
fn pub fmt(formatter: mut Formatter)

Formats self in a human-readable format for debugging purposes.

relative?

Show source code
Hide source code
fn pub inline relative? -> Bool {
  absolute?.false?
}
fn pub inline relative? -> Bool

Returns true if self is a relative path.

Examples

import std.uri (Path)

Path.new('/hello').get.relative? # => false
Path.new('hello').get.relative? # => true

size

Show source code
Hide source code
fn pub inline size -> Int {
  @value.size
}
fn pub inline size -> Int

Returns the size of self, before applying percent decoding.

Examples

import std.uri (Path)

Path.empty.size # => 0
Path.new('a%20b').get.size # => 5

Implemented traits

std.cmp.

Equal

impl Equal for Path
std.fmt.

Format

impl Format for Path