1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! A set of macros for using the extended dot operator. //! //! # Examples //! ## In areas where expression syntax is needed. //! ``` //! fn main() { //! extdot::expr!{ //! let v: i32 = -5; //! //! let v_abs = v.[it.abs()]; //!# assert_eq!(v_abs, 5); //! let v_pow = v.[it.pow(2)]; //!# assert_eq!(v_pow, 25); //! //! } //! } //! ``` //! //! ``` //! use serde::Deserialize; //! use std::{ fs::File, path::Path }; //! //! #[derive(Debug, Deserialize)] //! struct Point { //! x: i32, //! y: i32 //! } //! //! fn main() -> Result<(), Box<std::error::Error>>{ //! extdot::expr!{ //! let point: Point = //! Path::new("tests/data/point.json") //! .[File::open]? //! .[serde_json::from_reader]?; //! //!# assert_eq!(point.x, 4); //!# assert_eq!(point.y, 6); //! //! Ok(()) //! } //! } //! ``` //! //! ``` //! extdot::expr!{ //! let map = std::collections::HashMap::new().[ //! it.insert("key1", 13), //! it.insert("key2", 17), //! ]; //! //!# assert_eq!(map.get("key1"), Some(&13)); //!# assert_eq!(map.get("key2"), Some(&17)); //! } //! ``` //! ## In areas where item syntax is needed. //! ```rust //! use std::fmt; //! //! struct Example {} //! //! extdot::item!{ //! impl fmt::Display for Example { //! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { //! let v: i32 = -7; //! //! let v_abs = v.[it.abs()]; //!# assert_eq!(v_abs, 7); //! let v_pow = v.[it.pow(2)]; //!# assert_eq!(v_pow, 49); //! //! write!(f, "({}, {})", v_abs, v_pow) //! } //! } //! } //! //! fn main() { //! println!("{}", Example {}); //! } //! ``` use proc_macro_hack::proc_macro_hack; /// Allows the use of the extended dot notation in expressions. #[proc_macro_hack] pub use extdot_impl::expr; #[doc(inline)] pub use extdot_impl::item;