#Remove generic arguments from `Path`

1 messages · Page 1 of 1 (latest)

idle fable
#

Hello! What is the correct way to remove generic arguments from Path in syn?
std::collections::Vec<i32> into std::collections::Vec for example

warped cave
# idle fable Hello! What is the correct way to remove generic arguments from `Path` in `syn`?...

With mutation:

path.segments.last_mut().unwrap().arguments = <_>::default();
// or
mem::take(path.segments.last_mut().unwrap().arguments);

and then just use path.

Without mutation:
Either .clone() so as to allow mutation;
Or:

let Path { leading_colon, segments } = &path;
let each_ident = segments.iter().map(|it| &it.ident);
quote!(
    #leading_colon #( #each_ident )::*
)

if you don't mind losing the span of the intermediary ::