@@ -10,11 +10,8 @@ pub use position::{Located, Location, Position};
10
10
pub use reporter:: { CustomDiagnostic , DiagnosticKind } ;
11
11
use std:: io:: Write ;
12
12
13
- /// Print the input to stdout, and exit gracefully if `SIGPIPE` is received.
14
- /// Rust ignores `SIGPIPE` by default, converting pipe errors into `ErrorKind::BrokenPipe`
15
- pub fn print_to_stdout ( args : std:: fmt:: Arguments ) {
16
- let mut stdout = std:: io:: stdout ( ) ;
17
- if let Err ( e) = stdout. write_fmt ( args) {
13
+ pub fn print_args_or_exit < W : Write > ( args : std:: fmt:: Arguments , mut out : W ) {
14
+ if let Err ( e) = out. write_fmt ( args) {
18
15
if e. kind ( ) == std:: io:: ErrorKind :: BrokenPipe {
19
16
// Gracefully exit on broken pipe
20
17
std:: process:: exit ( 0 ) ;
@@ -24,6 +21,18 @@ pub fn print_to_stdout(args: std::fmt::Arguments) {
24
21
}
25
22
}
26
23
24
+ /// Print the input to stdout, and exit gracefully if `SIGPIPE` is received.
25
+ /// Rust ignores `SIGPIPE` by default, converting pipe errors into `ErrorKind::BrokenPipe`
26
+ pub fn print_to_stdout ( args : std:: fmt:: Arguments ) {
27
+ print_args_or_exit ( args, std:: io:: stdout ( ) ) ;
28
+ }
29
+
30
+ /// Print the input to stderr, and exit gracefully if `SIGPIPE` is received.
31
+ /// Rust ignores `SIGPIPE` by default, converting pipe errors into `ErrorKind::BrokenPipe`
32
+ pub fn print_to_stderr ( args : std:: fmt:: Arguments ) {
33
+ print_args_or_exit ( args, std:: io:: stderr ( ) ) ;
34
+ }
35
+
27
36
/// Macro to print formatted output to stdout
28
37
#[ macro_export]
29
38
macro_rules! print_to_stdout {
@@ -32,9 +41,26 @@ macro_rules! print_to_stdout {
32
41
} ;
33
42
}
34
43
44
+ /// Macro to print formatted output to stdout
35
45
#[ macro_export]
36
46
macro_rules! println_to_stdout {
37
47
( $( $arg: tt) * ) => {
38
48
noirc_errors:: print_to_stdout( format_args!( "{}\n " , format!( $( $arg) * ) ) )
39
49
} ;
40
50
}
51
+
52
+ /// Macro to print formatted output to stderr
53
+ #[ macro_export]
54
+ macro_rules! print_to_stderr {
55
+ ( $( $arg: tt) * ) => {
56
+ noirc_errors:: print_to_stderr( format_args!( $( $arg) * ) )
57
+ } ;
58
+ }
59
+
60
+ /// Macro to print formatted output to stderr
61
+ #[ macro_export]
62
+ macro_rules! println_to_stderr {
63
+ ( $( $arg: tt) * ) => {
64
+ noirc_errors:: print_to_stderr( format_args!( "{}\n " , format!( $( $arg) * ) ) )
65
+ } ;
66
+ }
0 commit comments