Skip to main content

ToCrateName

Trait ToCrateName 

Source
pub trait ToCrateName {
    type Output;

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

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

Required Associated Types§

Source

type Output

The resulting type, coming out of the conversion.

Required Methods§

Source

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

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

§Examples

Usage with syn::Ident:

let trait_name = Ident::new("DeriveHarvestype", Span::call_site());
let crate_name = trait_name.to_crate_name();
assert_eq!(crate_name, "derive_harvestype");

Usage with strings:

assert_eq!("THE_NEVERHOOD".to_crate_name(), "the_neverhood");
assert_eq!(String::from("AlexAndDerMurder").to_crate_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 ToCrateName for Ident

Available on crate feature syn only.
Source§

impl ToCrateName for str

Implementors§