Struct safe_network::url::Url [−][src]
pub struct Url { /* fields omitted */ }
Expand description
Represents a Url
A Url can be in one of two formats: nrs or xor. aka: nrsurl or xorurl
Here is a breakdown of how name terminology is used.
case 1: safe://a.b.shinything:
public_name() –> a.b.shinything top_name() –> shinything sub_names() –> a.b
case 2: safe://shinything:
public_name() –> shinything top_name() –> shinything sub_names() –> None
case 3: safe://a.b.hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc
public_name() –> a.b.hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc top_name() –> hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc sub_names() –> a.b
case 4: safe://hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc public_name() –> hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc top_name() –> hnyynyzhjjjatqkfkjux8maaojtj8r59aphcnue6a11qgecpcebidkywmybnc sub_names() –> None
Implementations
This implementation performs semi-rigorous validation, when parsing a URL using ::from_url(), ::from_xorurl(), or ::from_nrsurl().
However setters and new() do not enforce all the rules and using them with invalid input can result in serializing invalid URLs. GIGO.
As such, it is recommended to check validity by calling Url::validate() after instantiating or modifying.
Instantiates a new Url
Performs some basic validation checks, however it is possible to create invalid urls using this method.
Arguments
xor_name
- XorName hashnrs_name
- complete nrs name, or None for xorurltype_tag
- type tagdata_type
- DataTypecontent_type
- ContentTypepath
- must already be percent-encoded if Some. leading ‘/’ optional.xorurl_sub_names
- sub_names. ignored if nrs_name is present.query_string
- must already be percent-encoded, without ? separatorfragment
- url fragment, without # separatorcontent_version
- overrides value of “?v” in query-string if not None.
A non-member utility function to check if a media-type is currently supported by XOR-URL encoding
returns encoding version of xorurl
returns SAFE content type
sets the SAFE content type
Attempts to create a Register address.
returns public_name portion of xorurl using the default xorurl encoding.
public_name means sub_names + top_name
useful for retrieving xorurl name associated with an nrsurl.
For a different encoding, see name_to_base()
The public_name in url. Either nrs_name or xor_name.
eg a.b.name –> a.b.name
returns sub_names in an array slice
eg: a.b.name –> &[“a”, “b”]
sets sub_names portion of URL
returns path portion of URL, percent decoded
sets path portion of URL
input string must not be percent-encoded. The encoding is done internally.
leading slash is automatically added if necessary.
gets content version
This is a shortcut method for getting the “?v=” query param.
sets content version
This is a shortcut method for setting the “?v=” query param.
Arguments
version
- u64 representing value of ?v=
sets or unsets a key/val pair in query string.
if val is Some, then key=val will be set in query string. If there is more than one instance of key in query string, there will be only one after this call. If val is None, then the key will be removed from query string.
To set key without any value, pass Some<“”> as the val.
val
should not be percent-encoded. That is done internally.
Arguments
key
- name of url query string varval
- an option representing the value, or none.
sets query string.
If the query string contains ?v=
Arguments
query
- percent-encoded key/val pairs.
Retrieves query string
This contains the percent-encoded key/value pairs as seen in a url.
Retrieves query string, with ? separator if non-empty.
Queries a key from the query string.
Can return 0, 1, or many values because a given key may exist 0, 1, or many times in a URL query-string.
returns the last matching key from a query string.
eg in safe://name?color=red&age=5&color=green&color=blue blue would be returned when key is “color”.
returns the first matching key from a query string.
eg in safe://name?color=red&age=5&color=green&color=blue red would be returned when key is “color”.
sets url fragment
Retrieves url fragment, with # separator if non-empty.
returns type of this url.
for type of the linked content, see ::content_type()
serializes the URL to an XorUrl string.
This function may be called on an NrsUrl and the corresponding XorUrl will be returned.
serializes the URL to an NrsUrl string.
This function returns None when is_nrsurl() is false.
serializes entire xorurl using a particular base encoding.
serializes name portion of xorurl using a particular base encoding.
Utility function to perform url percent decoding.
Utility function to perform url percent encoding.
Validates that a Url instance can be parsed correctly.
Url::from_url() performs rigorous validation, however setters and new() do not enforce all the rules
This routine enables a caller to easily validate that the present instance passes all validation checks
pub fn encode(
xor_name: XorName,
nrs_name: Option<&str>,
type_tag: u64,
scope: Scope,
data_type: DataType,
content_type: ContentType,
path: Option<&str>,
sub_names: Option<Vec<String>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<VersionHash>,
base: XorUrlBase
) -> Result<String>
pub fn encode(
xor_name: XorName,
nrs_name: Option<&str>,
type_tag: u64,
scope: Scope,
data_type: DataType,
content_type: ContentType,
path: Option<&str>,
sub_names: Option<Vec<String>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<VersionHash>,
base: XorUrlBase
) -> Result<String>
A non-member encoder function for convenience in some cases
A non-member SafeKey encoder function for convenience
pub fn encode_blob(
xor_name: XorName,
scope: Scope,
content_type: ContentType,
base: XorUrlBase
) -> Result<String>
pub fn encode_blob(
xor_name: XorName,
scope: Scope,
content_type: ContentType,
base: XorUrlBase
) -> Result<String>
A non-member Blob encoder function for convenience
pub fn encode_register(
xor_name: XorName,
type_tag: u64,
scope: Scope,
content_type: ContentType,
base: XorUrlBase
) -> Result<String>
pub fn encode_register(
xor_name: XorName,
type_tag: u64,
scope: Scope,
content_type: ContentType,
base: XorUrlBase
) -> Result<String>
A non-member Register data URL encoder function for convenience
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Url
impl UnwindSafe for Url
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more