|
3 | 3 | use std::os::raw::c_char;
|
4 | 4 |
|
5 | 5 | #[cfg(feature = "log")]
|
6 |
| -use log::{Level, logger, Record}; |
| 6 | +use log::{Level, logger, Record, RecordBuilder}; |
7 | 7 |
|
8 | 8 | use crate::QString;
|
9 | 9 |
|
@@ -176,17 +176,18 @@ extern "C" fn log_capture(msg_type: QtMsgType,
|
176 | 176 | .file(file)
|
177 | 177 | .line(line)
|
178 | 178 | .module_path(None);
|
179 |
| - // (inner) match with single all-capturing arm is a hack that allows us |
| 179 | + // Match expression with single all-capturing arm is a hack that allows |
180 | 180 | // to extend the lifetime of a matched object for "a little longer".
|
| 181 | + // Passing an expression with temporaries as a function argument |
| 182 | + // works exactly the same way. |
181 | 183 | // Basically, it retains bounded temporary values together with their
|
182 | 184 | // intermediate values etc. This is also the way how println! macro works.
|
183 | 185 | match context.function() {
|
184 |
| - "" => match format_args!("{}", message) { |
185 |
| - args => logger().log(&record.args(args).build()), |
186 |
| - }, |
187 |
| - f => match format_args!("[in {}] {}", f, message) { |
188 |
| - args => logger().log(&record.args(args).build()), |
189 |
| - } |
| 186 | + "" => finish(record, format_args!("{}", message)), |
| 187 | + f => finish(record, format_args!("[in {}] {}", f, message)), |
| 188 | + } |
| 189 | + fn finish<'a>(mut record: RecordBuilder<'a>, args: std::fmt::Arguments<'a>) { |
| 190 | + logger().log(&record.args(args).build()) |
190 | 191 | }
|
191 | 192 | }
|
192 | 193 |
|
|
0 commit comments