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
/// Defines `print` macro that defines a print macro that uses the specified writer. /// /// The first argument specifies the generated macro name. /// The writer itself is specified by the rest arguments with the [`define_writer`] macros. /// /// See also [`define_println`] and [`define_try_print`] macros. /// /// # Examples /// /// ```rust /// let mut string = String::new(); /// custom_print::define_print!(cprint, fmt, |value: &str| string += value); /// /// assert_eq!(cprint!("value"), ()); /// assert_eq!(string, "value"); /// ``` #[macro_export] macro_rules! define_print { ( $name:ident, $($args:tt)* ) => { $crate::define_printlike!( $name, ::core::write, expect, $($args)* ); }; } /// Defines `println` macro that defines a println macro that uses the specified writer. /// /// The first argument specifies the generated macro name. /// The writer itself is specified by the rest arguments with the [`define_writer`] macros. /// /// See also [`define_print`] and [`define_try_println`] macros. /// /// # Examples /// /// ```rust /// let mut string = String::new(); /// custom_print::define_println!(cprintln, fmt, |value: &str| string += value); /// /// assert_eq!(cprintln!("value"), ()); /// assert_eq!(string, "value\n"); /// ``` #[macro_export] macro_rules! define_println { ( $name:ident, $($args:tt)* ) => { $crate::define_printlike!( $name, ::core::writeln, expect, $($args)* ); }; } /// Defines `try_print` macro that defines a fallible print macro that uses the specified writer. /// /// The first argument specifies the generated macro name. /// The writer itself is specified by the rest arguments with the [`define_writer`] macros. /// /// See also [`define_print`] and [`define_try_println`] macros. /// /// # Examples /// /// ```rust /// let mut string = String::new(); /// custom_print::define_try_print!(try_print, fmt, |value: &str| string += value); /// /// assert_eq!(try_print!("value"), Ok(())); /// assert_eq!(string, "value"); /// ``` #[macro_export] macro_rules! define_try_print { ( $name:ident, $($args:tt)* ) => { $crate::define_printlike!( $name, ::core::write, try, $($args)* ); }; } /// Defines `try_println` macro that defines /// a fallible println macro that uses the specified writer. /// /// The first argument specifies the generated macro name. /// The writer itself is specified by the rest arguments with the [`define_writer`] macros. /// /// See also [`define_println`] and [`define_try_print`] macros. /// /// # Examples /// /// ```rust /// let mut string = String::new(); /// custom_print::define_try_println!(try_println, fmt, |value: &str| string += value); /// /// assert_eq!(try_println!("value"), Ok(())); /// assert_eq!(string, "value\n"); /// ``` #[macro_export] macro_rules! define_try_println { ( $name:ident, $($args:tt)* ) => { $crate::define_printlike!( $name, ::core::writeln, try, $($args)* ); }; }