Skip to main content

rust_path_to_tokens

Function rust_path_to_tokens 

Source
pub fn rust_path_to_tokens(path: &str) -> TokenStream
Expand description

Parse a ::-separated Rust path string into a TokenStream, using raw identifiers (r#type) for segments that are Rust keywords.

Used instead of syn::parse_str::<syn::Type> because the latter cannot handle raw identifiers in path position: "google::type::LatLng" would fail to parse because type is a keyword, but this function correctly produces google::r#type::LatLng.

Path-position keywords (self, super, Self, crate) are emitted as plain idents (they’re valid in paths) — this differs from make_field_ident, which suffixes them with _.

Leading :: (absolute path, e.g. "::buffa::Message") is preserved.

§Panics

Panics (in debug) if path is empty.