1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! # Conversion utilities for namespaces
use Url;
/// Converts an URI into its RDNN-like equivalent.
///
/// Unless the input namespace URI is invalid or does not contain a domain name,
/// this function returns its RDNN-like equivalent. Domain name segments are reversed,
/// path segments order is preserved, all segments are joined with
/// the forward slash `/` character.
///
/// Returns `None` for namespace URIs that can not be converted to its RDNN-like equivalent.
///
/// # Examples
///
/// ```
/// use dsntk_common::to_rdnn;
///
/// let rdnn = to_rdnn("https://dsntk.io/system-1/component-1");
/// assert_eq!(Some("io/dsntk/system-1/component-1".to_string()), rdnn);
///
/// let rdnn = to_rdnn("https://dsntk.io");
/// assert_eq!(Some("io/dsntk".to_string()), rdnn);
///
/// let rdnn = to_rdnn("dsntk.io");
/// assert_eq!(None, rdnn);
///
/// ```