source_line

Macro source_line 

Source
source_line!() { /* proc-macro */ }
Expand description

Takes a type path as an argument and provides the source code path as a type parameter to the last element of the path. This has a very specific use case involving serde and large numbers of structs. Example:

    #![forbid(unsafe_code)]
    #![feature(adt_const_params)]
    #![allow(dead_code)]
    use std::fmt::{Display, Formatter};
    use std::fmt;

    extern crate const_source_position;

    // Phantom type
    enum Unconstructable<const SOURCE_LOCATION: &'static str> {}

    impl<const SOURCE_LOCATION: &'static str> Display for Unconstructable<SOURCE_LOCATION>  {
        fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result
        {
            write!(f, "{}", SOURCE_LOCATION)
        }
    }

    /*
        complicated type stuff, generics, macros, etc
    */

    fn generates_unconstructable_somehow() -> Box<dyn Display> {
        unimplemented!();
    }