extdot/
lib.rs

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