enum-path 0.1.0

Derive FromStr and Display impls for enums that follow a hierarchical path-like serialization scheme
Documentation
//! Hygiene tests for enum-path-derive: the derive must produce tokens that
//! compile even when the standard prelude is disabled and primitive type
//! names are shadowed in the surrounding scope.

#![no_implicit_prelude]
#![allow(dead_code, reason = "fields exist solely to exercise the derive")]
#![allow(
    non_camel_case_types,
    reason = "shadowing primitives is the point of this test"
)]

trait bool {}
trait char {}
trait f32 {}
trait f64 {}
trait i8 {}
trait i16 {}
trait i32 {}
trait i64 {}
trait i128 {}
trait isize {}
trait str {}
trait u8 {}
trait u16 {}
trait u32 {}
trait u64 {}
trait u128 {}
trait usize {}

#[derive(::enum_path::EnumPath)]
#[enum_path(FromStr, Display, rename_all = "snake_case")]
enum Inner
{
    Start,
    Stop,
}

#[derive(::enum_path::EnumPath)]
#[enum_path(FromStr, Display)]
enum Outer
{
    Plain,
    Nested(Inner),
    WithString(::std::string::String),
}

#[derive(::enum_path::EnumPath)]
#[enum_path(FromStr, Display, case_insensitive)]
enum Ci
{
    Start,
    Reload(::std::string::String),
}

#[test]
fn derives_compile_without_prelude()
{
    let i: Inner = <Inner as ::core::str::FromStr>::from_str("start").unwrap();
    let _: ::std::string::String = ::std::string::ToString::to_string(&i);

    let o: Outer = <Outer as ::core::str::FromStr>::from_str("Nested.start").unwrap();
    let _ = <Outer as ::core::str::FromStr>::from_str("WithString.hello").unwrap();
    let _: ::std::string::String = ::std::string::ToString::to_string(&o);

    let c: Ci = <Ci as ::core::str::FromStr>::from_str("StArT").unwrap();
    let _: ::std::string::String = ::std::string::ToString::to_string(&c);
}

mod shadow_core
{
    pub mod core
    {}
    pub mod std
    {}

    #[derive(::enum_path::EnumPath)]
    #[enum_path(FromStr, Display)]
    pub enum Foo
    {
        A,
        B(::std::string::String),
    }
}

#[test]
fn derives_compile_when_core_is_shadowed()
{
    let f: shadow_core::Foo = <shadow_core::Foo as ::core::str::FromStr>::from_str("A").unwrap();
    let _: ::std::string::String = ::std::string::ToString::to_string(&f);
}

mod renamed_crate
{
    pub use ::enum_path as renamed;

    #[derive(renamed::EnumPath)]
    #[enum_path(crate = renamed, FromStr, Display)]
    pub enum Renamed
    {
        A,
        B,
    }
}

#[test]
fn derive_compiles_when_crate_is_renamed()
{
    let r: renamed_crate::Renamed =
        <renamed_crate::Renamed as ::core::str::FromStr>::from_str("A").unwrap();
    let _: ::std::string::String = ::std::string::ToString::to_string(&r);
}