Struct sn_api::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
impl SafeUrl
[src]
impl SafeUrl
[src]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.
pub fn new(
xor_name: XorName,
nrs_name: Option<&str>,
type_tag: u64,
data_type: SafeDataType,
content_type: SafeContentType,
path: Option<&str>,
sub_names: Option<Vec<String, Global>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<u64>
) -> Result<SafeUrl, Error>
[src]
pub fn new(
xor_name: XorName,
nrs_name: Option<&str>,
type_tag: u64,
data_type: SafeDataType,
content_type: SafeContentType,
path: Option<&str>,
sub_names: Option<Vec<String, Global>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<u64>
) -> Result<SafeUrl, Error>
[src]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.
pub fn is_media_type_supported(media_type: &str) -> bool
[src]
pub fn encoding_version(&self) -> u64
[src]
pub fn encoding_version(&self) -> u64
[src]returns encoding version of xorurl
pub fn data_type(&self) -> SafeDataType
[src]
pub fn data_type(&self) -> SafeDataType
[src]returns SAFE data type
pub fn content_type(&self) -> SafeContentType
[src]
pub fn content_type(&self) -> SafeContentType
[src]returns SAFE content type
pub fn set_content_type(
&mut self,
content_type: SafeContentType
) -> Result<(), Error>
[src]
pub fn set_content_type(
&mut self,
content_type: SafeContentType
) -> Result<(), Error>
[src]sets the SAFE content type
pub fn register_address(&self) -> Result<Address, Error>
[src]
pub fn xorurl_public_name(&self) -> String
[src]
pub fn xorurl_public_name(&self) -> String
[src]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()
pub fn public_name(&self) -> &str
[src]
pub fn public_name(&self) -> &str
[src]The public_name in url. Either nrs_name or xor_name.
eg a.b.name –> a.b.name
pub fn sub_names_vec(&self) -> &[String]ⓘ
[src]
pub fn sub_names_vec(&self) -> &[String]ⓘ
[src]returns sub_names in an array slice
eg: a.b.name –> &[“a”, “b”]
pub fn set_sub_names(&mut self, sub_names: &str) -> Result<(), Error>
[src]
pub fn set_sub_names(&mut self, sub_names: &str) -> Result<(), Error>
[src]sets sub_names portion of URL
pub fn path_decoded(&self) -> Result<String, Error>
[src]
pub fn path_decoded(&self) -> Result<String, Error>
[src]returns path portion of URL, percent decoded
pub fn set_path(&mut self, path: &str)
[src]
pub fn set_path(&mut self, path: &str)
[src]sets path portion of URL
input string must not be percent-encoded. The encoding is done internally.
leading slash is automatically added if necessary.
pub fn content_version(&self) -> Option<u64>
[src]
pub fn content_version(&self) -> Option<u64>
[src]gets content version
This is a shortcut method for getting the “?v=” query param.
pub fn set_content_version(&mut self, version: Option<u64>)
[src]
pub fn set_content_version(&mut self, version: Option<u64>)
[src]sets content version
This is a shortcut method for setting the “?v=” query param.
Arguments
version
- u64 representing value of ?v=
pub fn set_query_key(
&mut self,
key: &str,
val: Option<&str>
) -> Result<(), Error>
[src]
pub fn set_query_key(
&mut self,
key: &str,
val: Option<&str>
) -> Result<(), Error>
[src]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.
pub fn set_query_string(&mut self, query: &str) -> Result<(), Error>
[src]
pub fn set_query_string(&mut self, query: &str) -> Result<(), Error>
[src]sets query string.
If the query string contains ?v=
Arguments
query
- percent-encoded key/val pairs.
pub fn query_string(&self) -> &str
[src]
pub fn query_string(&self) -> &str
[src]Retrieves query string
This contains the percent-encoded key/value pairs as seen in a url.
pub fn query_string_with_separator(&self) -> String
[src]
pub fn query_string_with_separator(&self) -> String
[src]Retrieves query string, with ? separator if non-empty.
pub fn query_pairs(&self) -> Vec<(String, String), Global>
[src]
pub fn query_pairs(&self) -> Vec<(String, String), Global>
[src]Retrieves all query pairs, percent-decoded.
pub fn query_key(&self, key: &str) -> Vec<String, Global>
[src]
pub fn query_key(&self, key: &str) -> Vec<String, Global>
[src]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.
pub fn query_key_last(&self, key: &str) -> Option<String>
[src]
pub fn query_key_last(&self, key: &str) -> Option<String>
[src]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”.
pub fn query_key_first(&self, key: &str) -> Option<String>
[src]
pub fn query_key_first(&self, key: &str) -> Option<String>
[src]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”.
pub fn set_fragment(&mut self, fragment: String)
[src]
pub fn set_fragment(&mut self, fragment: String)
[src]sets url fragment
pub fn fragment_with_separator(&self) -> String
[src]
pub fn fragment_with_separator(&self) -> String
[src]Retrieves url fragment, with # separator if non-empty.
pub fn safeurl_type(&self) -> &SafeUrlType
[src]
pub fn safeurl_type(&self) -> &SafeUrlType
[src]returns type of this SafeUrl.
for type of the linked content, see ::content_type()
pub fn to_xorurl_string(&self) -> String
[src]
pub fn to_xorurl_string(&self) -> String
[src]serializes the URL to an XorUrl string.
This function may be called on an NrsUrl and the corresponding XorUrl will be returned.
pub fn to_nrsurl_string(&self) -> Option<String>
[src]
pub fn to_nrsurl_string(&self) -> Option<String>
[src]serializes the URL to an NrsUrl string.
This function returns None when is_nrsurl() is false.
pub fn to_base(&self, base: XorUrlBase) -> String
[src]
pub fn to_base(&self, base: XorUrlBase) -> String
[src]serializes entire xorurl using a particular base encoding.
pub fn name_to_base(&self, base: XorUrlBase, include_subnames: bool) -> String
[src]
pub fn name_to_base(&self, base: XorUrlBase, include_subnames: bool) -> String
[src]serializes name portion of xorurl using a particular base encoding.
pub fn url_percent_decode(s: &str) -> Result<String, Error>
[src]
pub fn url_percent_decode(s: &str) -> Result<String, Error>
[src]Utility function to perform url percent decoding.
pub fn url_percent_encode(s: &str) -> String
[src]
pub fn url_percent_encode(s: &str) -> String
[src]Utility function to perform url percent encoding.
pub fn validate(&self) -> Result<(), Error>
[src]
pub fn validate(&self) -> Result<(), Error>
[src]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, Global>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<u64>,
base: XorUrlBase
) -> Result<String, Error>
[src]
xor_name: XorName,
nrs_name: Option<&str>,
type_tag: u64,
data_type: SafeDataType,
content_type: SafeContentType,
path: Option<&str>,
sub_names: Option<Vec<String, Global>>,
query_string: Option<&str>,
fragment: Option<&str>,
content_version: Option<u64>,
base: XorUrlBase
) -> Result<String, Error>
pub fn encode_safekey(
xor_name: XorName,
base: XorUrlBase
) -> Result<String, Error>
[src]
xor_name: XorName,
base: XorUrlBase
) -> Result<String, Error>
pub fn encode_blob(
xor_name: XorName,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String, Error>
[src]
xor_name: XorName,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String, Error>
pub fn encode_mutable_data(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String, Error>
[src]
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase
) -> Result<String, Error>
pub fn encode_sequence_data(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String, Error>
[src]
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String, Error>
pub fn encode_register(
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String, Error>
[src]
xor_name: XorName,
type_tag: u64,
content_type: SafeContentType,
base: XorUrlBase,
is_private: bool
) -> Result<String, Error>
Trait Implementations
impl<'de> Deserialize<'de> for SafeUrl
[src]
impl<'de> Deserialize<'de> for SafeUrl
[src]pub fn deserialize<__D>(
__deserializer: __D
) -> Result<SafeUrl, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<SafeUrl, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl Serialize for SafeUrl
[src]
impl Serialize for SafeUrl
[src]pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for SafeUrl
[src]
Auto Trait Implementations
impl RefUnwindSafe for SafeUrl
impl Send for SafeUrl
impl Sync for SafeUrl
impl Unpin for SafeUrl
impl UnwindSafe for SafeUrl
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,