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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
//! *Simple procedural macros to use [`textwrap`] utilities at compile time.* //! //! [`textwrap`]: https://github.com/mgeisler/textwrap //! //! [![TravisCI](https://img.shields.io/travis/com/althonos/textwrap-macros/master.svg?maxAge=600&style=flat-square)](https://travis-ci.com/althonos/textwrap-macros/branches) //! [![Codecov](https://img.shields.io/codecov/c/gh/althonos/textwrap-macros/master.svg?style=flat-square&maxAge=600)](https://codecov.io/gh/althonos/textwrap-macros) //! [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square&maxAge=2678400)](https://choosealicense.com/licenses/mit/) //! [![Source](https://img.shields.io/badge/source-GitHub-303030.svg?maxAge=2678400&style=flat-square)](https://github.com/althonos/textwrap-macros) //! [![Crate](https://img.shields.io/crates/v/textwrap-macros.svg?maxAge=600&style=flat-square)](https://crates.io/crates/textwrap-macros) //! [![Documentation](https://img.shields.io/badge/docs.rs-latest-4d76ae.svg?maxAge=2678400&style=flat-square)](https://docs.rs/textwrap-macros) //! [![Changelog](https://img.shields.io/badge/keep%20a-changelog-8A0707.svg?maxAge=2678400&style=flat-square)](https://github.com/althonos/textwrap-macros.rs/blob/master/CHANGELOG.md) //! //! ## Usage //! //! Either use the macros using the old-style `#[macro_use]` or import them as //! any other crate member: //! ```rust //! use textwrap_macros::dedent; //! //! const poem: &str = dedent!(r#" //! When we two parted //! In silence and tears, //! Half broken-hearted //! To sever for years, //! Pale grew thy cheek and cold, //! Colder thy kiss; //! Truly that hour foretold //! Sorrow to this. //! "#); //! ``` //! //! Checkout the [documentation of the original library](https://docs.rs/textwrap/0.11.0/textwrap/) //! for more information about the behaviour of each of the wrapped functions. //! //! ## Changelog //! //! This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) //! and provides a [changelog](https://github.com/althonos/textwrap-macros/blob/master/CHANGELOG.md) //! in the [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) format. extern crate proc_macro_hack; #[proc_macro_hack::proc_macro_hack] /// Removes common leading whitespace from each line. /// /// This macro will look at each non-empty line and determine the maximum /// amount of whitespace that can be removed from all lines, and create a /// new string literal in place of the old one. /// /// # Usage /// ```rust,ignore /// dedent!($text: lit &str) -> lit &str /// ``` /// /// # Example /// ```rust /// use textwrap_macros::dedent; /// /// const X: &str = dedent!(" /// 1st line /// 2nd line /// 3rd line /// "); /// /// assert_eq!(X, " /// 1st line /// 2nd line /// 3rd line /// "); /// ``` /// /// See also [`textwrap::dedent`](https://docs.rs/textwrap/latest/textwrap/fn.dedent.html). pub use textwrap_macros_impl::dedent; #[proc_macro_hack::proc_macro_hack] /// Add prefix to each non-empty line. /// /// Empty lines (consisting only of whitespaces, with respect to /// [`char.is_whitespace`](https://doc.rust-lang.org/std/primitive.char.html#method.is_whitespace)) /// are not indented but replaced by a single newline character `\n`. Leading /// and trailing whitespace on non-empty lines is kept unchanged. /// /// # Usage /// ```rust,ignore /// indent!($text: lit &str, $prefix: lit &str) -> lit &str /// ``` /// /// # Example /// ```rust /// use textwrap_macros::indent; /// /// const Y: &str = indent!(" /// Foo /// Bar /// ", "-> "); /// /// assert_eq!(Y, " /// -> Foo /// -> Bar /// "); /// ``` /// /// See also [textwrap::indent](https://docs.rs/textwrap/latest/textwrap/fn.indent.html). pub use textwrap_macros_impl::indent; #[proc_macro_hack::proc_macro_hack] /// Fill a line of text at `width` characters. /// /// Strings are wrapped based on their displayed width, not their size in bytes. /// The result is a string with newlines between each line. Use `wrap` if /// you need access to the individual lines. /// /// # Usage /// ```rust, ignore /// fill!($text: lit &str, $width: lit usize) -> lit &str /// ``` /// /// # Example /// ```rust /// use textwrap_macros::fill; /// /// const FILLED: &str = fill!("Memory safety without garbage collection.", 15); /// assert_eq!(FILLED, "Memory safety\nwithout garbage\ncollection."); /// ``` /// /// See also [textwrap::fill](https://docs.rs/textwrap/latest/textwrap/fn.fill.html). pub use textwrap_macros_impl::fill; #[proc_macro_hack::proc_macro_hack] /// Wrap a line of text at width characters. /// /// Strings are wrapped based on their displayed width, not their size in /// bytes. /// /// # Usage /// ```rust, ignore /// wrap!($text: lit &str, $width: lit usize) -> lit &[ lit &str ] /// ``` /// /// # Example /// ```rust /// use textwrap_macros::wrap; /// /// const LINES: &[&str] = wrap!("Concurrency without data races.", 15); /// assert_eq!(LINES, ["Concurrency", "without data", "races."]); /// ``` pub use textwrap_macros_impl::wrap;