ockam_core/routing/
macros.rs

1/// Creates a new [`Route`] from a comma-delimited list of [`Address`]es.
2///
3/// The `route!` macro allows a `Route` to be defined with the same
4/// syntax as array expressions:
5///
6/// ```
7/// # use ockam_core::{Route, route, Address};
8/// # use ockam_core::compat::rand::random;
9/// let address4: Address = random();
10/// let route = route!["address1", "address2", "address3".to_string(), address4];
11/// ```
12///
13/// [`Address`]: Into<Route>
14/// [`Route`]: crate::Route
15#[macro_export]
16macro_rules! route {
17    ($($x:expr),* $(,)?) => ({
18        #[allow(unused_mut)]
19        let mut r = $crate::Route::new();
20        $(r = r.append($x);)*
21        $crate::Route::from(r)
22    });
23}
24
25#[cfg(test)]
26mod tests {
27    use crate::compat::rand::random;
28    use crate::Address;
29
30    #[test]
31    fn test1() {
32        let _route = route![];
33    }
34
35    #[test]
36    fn test2() {
37        use crate::compat::string::ToString;
38        let address: Address = random();
39        let _route1 = route!["str", "STR2", "STR3".to_string(), address];
40    }
41
42    #[test]
43    fn test3() {
44        let _route = route!["str",];
45    }
46}