drt-sc-derive 0.0.2

Dharitri smart contract API procedural macros
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use syn::{punctuated::Punctuated, token::PathSep};

/// Splits off the last part of a path from the rest.
/// e.g. `some::module::Item` will be split into `some::module::` and `Item`.
/// Note that the last `::` is retained in the first part of the result.
/// Returns none if no module is specified.
/// The method is designed for contexts where explicit module specification is required.
pub fn split_path_last(
    path: &syn::Path,
) -> Option<(Punctuated<syn::PathSegment, PathSep>, syn::PathSegment)> {
    if path.segments.len() >= 2 {
        let mut leading_segments = path.segments.clone();
        let last_segment = leading_segments.pop().unwrap().into_value();
        Some((leading_segments, last_segment))
    } else {
        None
    }
}