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 hash
  • nrs_name - complete nrs name, or None for xorurl
  • type_tag - type tag
  • data_type - SafeDataType
  • content_type - SafeContentType
  • path - 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 ? separator
  • fragment - url fragment, without # separator
  • content_version - overrides value of “?v” in query-string if not None.

Parses a safe url into SafeUrl

Arguments

  • url - either nrsurl or xorurl

Parses an NRS Url into SafeUrl

Arguments

  • nrsurl - an nrsurl.

Parses a XorUrl into SafeUrl

Arguments

  • xorurl - an xorurl.

The url scheme. Only ‘safe’ scheme is presently supported.

returns encoding version of xorurl

returns SAFE data type

returns SAFE content type

sets the SAFE content type

returns XorName

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 top name of name field.

eg: a.b.name –> name

returns sub_names

eg: a.b.name –> a.b

returns sub_names in an array slice

eg: a.b.name –> &[“a”, “b”]

sets sub_names portion of URL

returns XorUrl type tag

returns path portion of URL, percent encoded (unmodified).

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 var
  • val - an option representing the value, or none.

sets query string.

If the query string contains ?v= then it will take effect as if set_content_version() had been called.

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.

Retrieves all query pairs, percent-decoded.

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, without # separator

Retrieves url fragment, with # separator if non-empty.

returns true if an NrsUrl, false if an XorUrl

returns true if an XorUrl, false if an NrsUrl

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

serializes the URL to a string.

an NrsUrl will be serialized in NrsUrl form. an XorUrl will be serialized in XorUrl form.

See also:

  • ::to_xorurl_string()
  • ::to_nrs_url_string()

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.