Struct sn_url::SafeUrl [−][src]
pub struct SafeUrl { /* fields omitted */ }
Expand description
Represents a SafeUrl
A SafeUrl 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 SafeUrl::validate() after instantiating or modifying.
Instantiates a new SafeUrl
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
- SafeDataTypecontent_type
- SafeContentTypepath
- 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.
returns encoding version of xorurl
returns SAFE data type
returns SAFE content type
sets the SAFE content type
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 SafeUrl.
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 SafeUrl instance can be parsed correctly.
SafeUrl::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,
data_type: SafeDataType,
content_type: SafeContentType,
path: Option<&str>,
sub_names: Option<Vec<String>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<u64>,
base: XorUrlBase
) -> Result<String>
pub fn encode_blob(
xor_name: XorName,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String>
pub fn encode_mutable_data(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String>
pub fn encode_sequence_data(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String>
pub fn encode_register(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String>
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
Auto Trait Implementations
impl RefUnwindSafe for SafeUrl
impl UnwindSafe for SafeUrl
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V