case!() { /* proc-macro */ }Expand description
Small macro that converts the input path to a given case.
The general accepted format is: case!(path::to::Type => Case)
Hereby
path::to::Typecan be any path. It does not need to exist.=>is just a fat arrow that separates the two parameters.Caseis any path that points to any value of theconvert_casecrate’sCaseenum.
This macro always expands to a &str literal (LitStr).
§Examples
The identifier given does not need to be an existing type:
use mongodb_ext_derive::case;
// `MyImaginaryType` is not imported, but works anyways
// `Case` is not imported, but works anyways
assert_eq!(
case!(MyImaginaryType => Case::Camel),
"myImaginaryType"
);If a path is given, only the last element will be parsed:
use mongodb_ext_derive::case;
assert_eq!(
case!(std::collection::HashMap => Snake),
"hash_map"
);use mongodb_ext_derive::case;
assert_eq!(
case!(std::this::r#type::does::not::exist::THIS_CONSTANT_DOES_NOT_EXIST => Pascal),
"ThisConstantDoesNotExist"
);
assert_eq!(
case!(std::this::r#type::does::not::exist::this_function_does_not_exist => Title),
"This Function Does Not Exist"
);
assert_eq!(
case!(std::this::r#type::does::not::exist::ThisTypeDoesNotExist => Camel),
"thisTypeDoesNotExist"
);