Skip to main content

ToVariableName

Trait ToVariableName 

Source
pub trait ToVariableName {
    type Output;

    // Required method
    fn to_variable_name(&self) -> Self::Output;
}
Expand description

Types convertible to the letter casing corresponding to names of variables.

Required Associated Types§

Source

type Output

The resulting type, coming out of the conversion.

Required Methods§

Source

fn to_variable_name(&self) -> Self::Output

Converts self to the letter casing of variable names (snake_case). Adheres to the general conversion rules.

§Examples

Usage with syn::Ident:

let struct_name = Ident::new("BinarySearchTree", Span::call_site());
let variable_name = struct_name.to_variable_name();
assert_eq!(variable_name, "binary_search_tree");

Usage with strings:

assert_eq!("BUGS_PER_LINE".to_variable_name(), "bugs_per_line");
assert_eq!(String::from("AlexAndDerMurder").to_variable_name(), "alex_and_der_murder");
§Panics

Whether this method panics depends on the implementator, see their documentation for that. However, implementations from this crate never panic.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ToVariableName for Ident

Available on crate feature syn only.
Source§

impl ToVariableName for str

Implementors§