URL Standard for Navi.
Parse a URL from string
use std.url.Url;
let my_url = try? Url.parse("https://navi-lang.org");
my_url?.to_string(); // "https://navi-lang.org"
[src]
pub fn parse(str: string): Url throws UrlError {
return try _Url.parse(str) as Url;
}
Parse a string into a Url
object, if parse failed return nil
.
[src]
pub fn parse(str: string): Url throws UrlError {
return try _Url.parse(str) as Url;
}
Parse a string into a Url
object, if parse failed return nil
.
Parse a string into a Url
object, if parse failed return nil
.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
my_url.to_string(); // "https://navi-lang.org"
let my_url = try? Url.parse("foo");
assert my_url.is_nil();
[src]
pub fn to_string(self): string {
return (self as _Url).to_string();
}
Return the string of the URL.
[src]
pub fn to_string(self): string {
return (self as _Url).to_string();
}
Return the string of the URL.
Return the string of the URL.
If the url is end with /
, the /
will be removed.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
assert_eq my_url.to_string(), "https://navi-lang.org";
[src]
pub fn scheme(self): string {
return (self as _Url).attr(AttrId.Schema as int);
}
The scheme of the URL.
[src]
pub fn scheme(self): string {
return (self as _Url).attr(AttrId.Schema as int);
}
The scheme of the URL.
The scheme of the URL.
The URL scheme must be valid.
If this URL is cannot-be-a-base and the new scheme is one of http
, https
, ws
, wss
or ftp
.
For example: [a-zA-Z][a-zA-Z0-9+.-]+
If the scheme is not valid, the scheme will not be changed.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
assert_eq my_url.scheme(), "https";
my_url.set_scheme("http");
assert_eq my_url.to_string(), "http://navi-lang.org";
let my_url = try! Url.parse("navi://navi-lang.org");
my_url.set_scheme("vscode");
assert_eq my_url.to_string(), "vscode://navi-lang.org";
Cannot change URL's scheme from https
to mailto
or other custom schemes:
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
my_url.set_scheme("foo"); // this will not changed
assert_eq my_url.scheme(), "https";
Cannot change URL's scheme from mailto
(cannot-be-a-base) to https
:
use std.url.Url;
let my_url = try! Url.parse("mailto:foo@example");
my_url.set_scheme("https"); // this will not changed
my_url.scheme(); // "mailto"
set_scheme
pub fn set_scheme(self, val: string): Url
[src]
pub fn set_scheme(self, val: string): Url {
(self as _Url).set_attr(AttrId.Schema as int, val);
return self;
}
Set the scheme of the URL, and return self.
set_scheme
pub fn set_scheme(self, val: string): Url
[src]
pub fn set_scheme(self, val: string): Url {
(self as _Url).set_attr(AttrId.Schema as int, val);
return self;
}
Set the scheme of the URL, and return self.
Set the scheme of the URL, and return self.
see Url.schema
for more details.
[src]
pub fn host(self): string {
return (self as _Url).attr(AttrId.Host as int);
}
The host of the URL.
[src]
pub fn host(self): string {
return (self as _Url).attr(AttrId.Host as int);
}
The host of the URL.
The host of the URL.
This is not including the port.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
assert_eq my_url.host(), "navi-lang.org";
let my_url = try! Url.parse("https://navi-lang.org:8080");
assert_eq my_url.host(), "navi-lang.org";
my_url.set_host("github.com");
assert_eq my_url.to_string(), "https://github.com:8080";
[src]
pub fn set_host(self, val: string): Url {
(self as _Url).set_attr(AttrId.Host as int, val);
return self;
}
Set the host of the URL, and return self.
[src]
pub fn set_host(self, val: string): Url {
(self as _Url).set_attr(AttrId.Host as int, val);
return self;
}
Set the host of the URL, and return self.
Set the host of the URL, and return self.
see Url.host
for more details.
[src]
pub fn port(self): int {
return (self as _Url).port();
}
The port of the URL.
[src]
pub fn port(self): int {
return (self as _Url).port();
}
The port of the URL.
The port of the URL.
If there no port part in the URL, will use the default port of the scheme.
The port must be in the range 0..=65535
, if port is invalid, this will not be changed.
protocol | port |
---|---|
"ftp" | 21 |
"file" | 0 |
"http" | 80 |
"https" | 443 |
"ws" | 80 |
"wss" | 443 |
If there still no port matched with the scheme, will return 0
.
use std.url.Url;
let my_url = try! Url.parse("http://navi-lang.org");
assert_eq my_url.port(), 80;
let my_url = try! Url.parse("https://navi-lang.org");
assert_eq my_url.port(), 443;
let my_url = try! Url.parse("https://navi-lang.org:8080/docs");
assert_eq my_url.port(), 8080;
my_url.set_port(80);
assert_eq my_url.to_string(), "https://navi-lang.org:80/docs";
[src]
pub fn set_port(self, val: int): Url {
(self as _Url).set_port(val);
return self;
}
Set the port of the URL, and return self.
[src]
pub fn set_port(self, val: int): Url {
(self as _Url).set_port(val);
return self;
}
Set the port of the URL, and return self.
Set the port of the URL, and return self.
see Url.port
for more details.
[src]
pub fn path(self): string {
return (self as _Url).attr(AttrId.Path as int);
}
The path of the URL.
nvuse std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org/docs/getting-started?locale=en");
assert_eq my_url.path(), "/docs/getting-started";
[src]
pub fn path(self): string {
return (self as _Url).attr(AttrId.Path as int);
}
The path of the URL.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org/docs/getting-started?locale=en");
assert_eq my_url.path(), "/docs/getting-started";
The path of the URL.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org/docs/getting-started?locale=en");
assert_eq my_url.path(), "/docs/getting-started";
my_url.set_path("/docs");
assert_eq my_url.to_string(), "https://navi-lang.org/docs?locale=en";
[src]
pub fn set_path(self, val: string): Url {
(self as _Url).set_attr(AttrId.Path as int, val);
return self;
}
Set the path of the URL, and return self.
[src]
pub fn set_path(self, val: string): Url {
(self as _Url).set_attr(AttrId.Path as int, val);
return self;
}
Set the path of the URL, and return self.
Set the path of the URL, and return self.
see Url.path
for more details.
[src]
pub fn query(self): string {
return (self as _Url).attr(AttrId.Query as int);
}
The query string of the URL.
[src]
pub fn query(self): string {
return (self as _Url).attr(AttrId.Query as int);
}
The query string of the URL.
The query string of the URL.
If there is no query string, return ""
.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org/docs/getting-started?locale=en&foo=bar");
assert_eq my_url.query(), "locale=en&foo=bar";
my_url.set_query("abc=123&def=456");
assert_eq my_url.to_string(), "https://navi-lang.org/docs/getting-started?abc=123&def=456";
[src]
pub fn set_query(self, val: string): Url {
(self as _Url).set_attr(AttrId.Query as int, val);
return self;
}
Set the query string of the URL, and return self.
[src]
pub fn set_query(self, val: string): Url {
(self as _Url).set_attr(AttrId.Query as int, val);
return self;
}
Set the query string of the URL, and return self.
Set the query string of the URL, and return self.
see Url.query
for more details.
[src]
pub fn fragment(self): string {
return (self as _Url).attr(AttrId.Fragment as int);
}
The fragment of the URL.
[src]
pub fn fragment(self): string {
return (self as _Url).attr(AttrId.Fragment as int);
}
The fragment of the URL.
The fragment of the URL.
If there is no fragment, return ""
.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org/docs/getting-started#installation");
assert_eq my_url.fragment(), "installation";
my_url.set_fragment("usage");
assert_eq my_url.to_string(), "https://navi-lang.org/docs/getting-started#usage";
set_fragment
pub fn set_fragment(self, val: string): Url
[src]
pub fn set_fragment(self, val: string): Url {
(self as _Url).set_attr(AttrId.Fragment as int, val);
return self;
}
Set the fragment of the URL, and return self.
set_fragment
pub fn set_fragment(self, val: string): Url
[src]
pub fn set_fragment(self, val: string): Url {
(self as _Url).set_attr(AttrId.Fragment as int, val);
return self;
}
Set the fragment of the URL, and return self.
Set the fragment of the URL, and return self.
see Url.fragment
for more details.
[src]
pub fn username(self): string {
return (self as _Url).attr(AttrId.Username as int);
}
The username of the URL.
[src]
pub fn username(self): string {
return (self as _Url).attr(AttrId.Username as int);
}
The username of the URL.
The username of the URL.
If there is no username, return ""
.
If the URL is cannot-be-a-base, or URL not have a host, the username will not be changed.
use std.url.Url;
let my_url = try! Url.parse("redis://localhost:6379");
assert_eq my_url.username(), "";
let my_url = try! Url.parse("redis://username@localhost:6379");
assert_eq my_url.username(), "username";
my_url.set_username("someone");
assert_eq my_url.to_string(), "redis://someone@localhost:6379";
set_username
pub fn set_username(self, val: string): Url
[src]
pub fn set_username(self, val: string): Url {
(self as _Url).set_attr(AttrId.Username as int, val);
return self;
}
Set the username of the URL, and return self.
set_username
pub fn set_username(self, val: string): Url
[src]
pub fn set_username(self, val: string): Url {
(self as _Url).set_attr(AttrId.Username as int, val);
return self;
}
Set the username of the URL, and return self.
Set the username of the URL, and return self.
see Url.username
for more details.
[src]
pub fn password(self): string {
return (self as _Url).attr(AttrId.Password as int);
}
The password of the URL.
[src]
pub fn password(self): string {
return (self as _Url).attr(AttrId.Password as int);
}
The password of the URL.
The password of the URL.
If there is no password, return ""
.
If the URL is cannot-be-a-base, or URL not have a host, the password will not be changed.
use std.url.Url;
let my_url = try! Url.parse("redis://username@localhost:6379");
assert_eq my_url.password(), "";
let my_url = try! Url.parse("redis://username:123456@localhost:6379");
assert_eq my_url.password(), "123456";
my_url.set_password("654321");
assert_eq my_url.to_string(), "redis://username:654321@localhost:6379";
set_password
pub fn set_password(self, val: string): Url
[src]
pub fn set_password(self, val: string): Url {
(self as _Url).set_attr(AttrId.Password as int, val);
return self;
}
Set the password of the URL, and return self.
set_password
pub fn set_password(self, val: string): Url
[src]
pub fn set_password(self, val: string): Url {
(self as _Url).set_attr(AttrId.Password as int, val);
return self;
}
Set the password of the URL, and return self.
Set the password of the URL, and return self.
see Url.password
for more details.
[src]
pub fn origin(self): string {
return (self as _Url).origin();
}
Return the origin of this URL (https://url.spec.whatwg.org/#origin)
[src]
pub fn origin(self): string {
return (self as _Url).origin();
}
Return the origin of this URL (https://url.spec.whatwg.org/#origin)
Return the origin of this URL (https://url.spec.whatwg.org/#origin)
use std.url.Url;
let my_url = try! Url.parse("http://navi-lang.org");
assert_eq my_url.origin(), "http://navi-lang.org";
let my_url = try! Url.parse("http://navi-lang.org/foo/bar?id=1&name=foo");
assert_eq my_url.origin(), "http://navi-lang.org";
let my_url = try! Url.parse("https://navi-lang.org:8080/foo/bar?id=1&name=foo#this-is-hash");
assert_eq my_url.origin(), "https://navi-lang.org:8080";
let my_url = try! Url.parse("navi://navi-lang.org:8080/foo/bar");
assert_eq my_url.origin(), "";
let my_url = try! Url.parse("blob:https://navi-lang.org:8080/foo/bar");
assert_eq my_url.origin(), "https://navi-lang.org:8080";
let my_url = try! Url.parse("file:///foo/bar");
assert_eq my_url.origin(), "";
[src]
pub fn authority(self): string {
return (self as _Url).authority();
}
Return the authority of this URL as an ASCII string. (https://url.spec.whatwg.org/#authority)
[src]
pub fn authority(self): string {
return (self as _Url).authority();
}
Return the authority of this URL as an ASCII string. (https://url.spec.whatwg.org/#authority)
Return the authority of this URL as an ASCII string. (https://url.spec.whatwg.org/#authority)
Non-ASCII domains are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs. IPv6 addresses are given between [ and ] brackets. Ports are omitted if they match the well known port of a special URL.
Username and password are percent-encoded.
use std.url.Url;
let my_url = try! Url.parse("http://navi-lang.org/foo/bar");
assert_eq my_url.authority(), "navi-lang.org";
let my_url = try! Url.parse("http://navi-lang.org:8080/foo/bar");
assert_eq my_url.authority(), "navi-lang.org:8080";
[src]
pub fn join(self, path: string): Url {
return (self as _Url).join(path) as Url;
}
Join the URL with another string, return the new URL.
[src]
pub fn join(self, path: string): Url {
return (self as _Url).join(path) as Url;
}
Join the URL with another string, return the new URL.
Join the URL with another string, return the new URL.
use std.url.Url;
let my_url = try! Url.parse("https://navi-lang.org");
my_url = my_url.join("/docs");
assert_eq my_url.to_string(), "https://navi-lang.org/docs";