log!() { /* proc-macro */ }Expand description
Impl filler:
Generates an implementation that simply logs the parameters and returns ().
§Syntax
#[portrait::fill(portrait::log($logger:path))]You can also specify leading parameters to the macro call:
#[portrait::fill(portrait::log($logger:path, $($args:expr),*))]$loggeris the path to the macro for logging, e.g.log::infoor [println!].$argsare the arguments passed to the macro before the format template, e.g. the log level inlog::logor the writer inwriteln!.
Associated constants are not supported.
Associated types are always ()
(we assume to be the return likely type of $logger).
Currently, this macro does not properly support #[cfg] on arguments yet.
§Example
// Imports required for calling the `write!` macro
use std::fmt::{self, Write};
#[portrait::make]
trait Foo {
type Bar;
fn qux(&mut self, i: i64) -> Self::Bar;
}
#[derive(Default)]
struct Receiver {
buffer: String,
}
#[portrait::fill(portrait::log(
write -> fmt::Result,
&mut self.buffer,
))]
impl Foo for Receiver {}
let mut recv = Receiver::default();
recv.qux(3);
assert_eq!(recv.buffer.as_str(), "qux(3)");