Skip to content

Commit 8b5cbfb

Browse files
committed
[bindings] Drop the lifetime bound on Record for bindings builds
Because log `Record`s are now being passed by ownership to `log`, the bindings get quite annoyed that there's a lifetime hanging around. We already don't use this lifetime in bindings (the `FormatArgs` is converted to a string and stored on the heap), so we can just drop the lifetime, even though it requires some macro'ing of the struct definition to do so.
1 parent 4bab9c8 commit 8b5cbfb

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/util/logger.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ impl Level {
9191
}
9292
}
9393

94+
macro_rules! impl_record {
95+
($($args: lifetime)?, $($nonstruct_args: lifetime)?) => {
9496
/// A Record, unit of logging output with Metadata to enable filtering
9597
/// Module_path, file, line to inform on log's source
9698
#[derive(Clone, Debug)]
97-
pub struct Record<'a> {
99+
pub struct Record<$($args)?> {
98100
/// The verbosity level of the message.
99101
pub level: Level,
100102
/// The node id of the peer pertaining to the logged record.
@@ -118,22 +120,17 @@ pub struct Record<'a> {
118120
pub file: &'static str,
119121
/// The line containing the message.
120122
pub line: u32,
121-
122-
#[cfg(c_bindings)]
123-
/// We don't actually use the lifetime parameter in C bindings (as there is no good way to
124-
/// communicate a lifetime to a C, or worse, Java user).
125-
_phantom: core::marker::PhantomData<&'a ()>,
126123
}
127124

128-
impl<'a> Record<'a> {
125+
impl<$($args)?> Record<$($args)?> {
129126
/// Returns a new Record.
130127
///
131128
/// This is not exported to bindings users as fmt can't be used in C
132129
#[inline]
133-
pub fn new(
130+
pub fn new<$($nonstruct_args)?>(
134131
level: Level, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>,
135132
args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32
136-
) -> Record<'a> {
133+
) -> Record<$($args)?> {
137134
Record {
138135
level,
139136
peer_id,
@@ -145,11 +142,14 @@ impl<'a> Record<'a> {
145142
module_path,
146143
file,
147144
line,
148-
#[cfg(c_bindings)]
149-
_phantom: core::marker::PhantomData,
150145
}
151146
}
152147
}
148+
} }
149+
#[cfg(not(c_bindings))]
150+
impl_record!('a, );
151+
#[cfg(c_bindings)]
152+
impl_record!(, 'a);
153153

154154
/// A trait encapsulating the operations required of a logger.
155155
pub trait Logger {

0 commit comments

Comments
 (0)