Skip to content

Commit 594c101

Browse files
committed
Prefix usage of exported macros with $crate so users don't have to use lightning::*; when using them
1 parent 4bab16e commit 594c101

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
#[macro_export]
1515
macro_rules! encode_tlv {
1616
($stream: expr, $type: expr, $field: expr, (default_value, $default: expr)) => {
17-
encode_tlv!($stream, $type, $field, required)
17+
$crate::encode_tlv!($stream, $type, $field, required)
1818
};
1919
($stream: expr, $type: expr, $field: expr, required) => {
2020
BigSize($type).write($stream)?;
2121
BigSize($field.serialized_length() as u64).write($stream)?;
2222
$field.write($stream)?;
2323
};
2424
($stream: expr, $type: expr, $field: expr, vec_type) => {
25-
encode_tlv!($stream, $type, ser::VecWriteWrapper(&$field), required);
25+
$crate::encode_tlv!($stream, $type, ser::VecWriteWrapper(&$field), required);
2626
};
2727
($stream: expr, $optional_type: expr, $optional_field: expr, option) => {
2828
if let Some(ref field) = $optional_field {
@@ -45,7 +45,7 @@ macro_rules! encode_tlv_stream {
4545
};
4646

4747
$(
48-
encode_tlv!($stream, $type, $field, $fieldty);
48+
$crate::encode_tlv!($stream, $type, $field, $fieldty);
4949
)*
5050

5151
#[allow(unused_mut, unused_variables, unused_assignments)]
@@ -162,7 +162,7 @@ macro_rules! check_missing_tlv {
162162
#[macro_export]
163163
macro_rules! decode_tlv {
164164
($reader: expr, $field: ident, (default_value, $default: expr)) => {{
165-
decode_tlv!($reader, $field, required)
165+
$crate::decode_tlv!($reader, $field, required)
166166
}};
167167
($reader: expr, $field: ident, required) => {{
168168
$field = ser::Readable::read(&mut $reader)?;
@@ -218,7 +218,7 @@ macro_rules! decode_tlv_stream {
218218
}
219219
// As we read types, make sure we hit every required type between last_seen_type and typ:
220220
$({
221-
check_tlv_order!(last_seen_type, typ, $type, $field, $fieldty);
221+
$crate::check_tlv_order!(last_seen_type, typ, $type, $field, $fieldty);
222222
})*
223223
last_seen_type = Some(typ.0);
224224

@@ -227,7 +227,7 @@ macro_rules! decode_tlv_stream {
227227
let mut s = ser::FixedLengthReader::new(&mut stream_ref, length.0);
228228
match typ.0 {
229229
$($type => {
230-
decode_tlv!(s, $field, $fieldty);
230+
$crate::decode_tlv!(s, $field, $fieldty);
231231
if s.bytes_remain() {
232232
s.eat_remaining()?; // Return ShortRead if there's actually not enough bytes
233233
return Err(DecodeError::InvalidValue);
@@ -242,16 +242,14 @@ macro_rules! decode_tlv_stream {
242242
}
243243
// Make sure we got to each required type after we've read every TLV:
244244
$({
245-
check_missing_tlv!(last_seen_type, $type, $field, $fieldty);
245+
$crate::check_missing_tlv!(last_seen_type, $type, $field, $fieldty);
246246
})*
247247
} }
248248
}
249249

250250
/// Implements Readable/Writeable for a struct. This macro also handles (de)serialization of TLV records.
251251
/// # Example
252252
/// ```
253-
/// use lightning::*;
254-
///
255253
/// #[derive(Debug)]
256254
/// pub struct LightningMessage {
257255
/// pub to: String,
@@ -262,7 +260,7 @@ macro_rules! decode_tlv_stream {
262260
/// pub street_number: Option<u16>,
263261
/// }
264262
///
265-
/// impl_writeable_msg!(LightningMessage, {
263+
/// lightning::impl_writeable_msg!(LightningMessage, {
266264
/// to,
267265
/// note,
268266
/// secret_number,
@@ -277,15 +275,15 @@ macro_rules! impl_writeable_msg {
277275
impl $crate::util::ser::Writeable for $st {
278276
fn write<W: $crate::util::ser::Writer>(&self, w: &mut W) -> Result<(), $crate::io::Error> {
279277
$( self.$field.write(w)?; )*
280-
encode_tlv_stream!(w, {$(($type, self.$tlvfield, $fieldty)),*});
278+
$crate::encode_tlv_stream!(w, {$(($type, self.$tlvfield, $fieldty)),*});
281279
Ok(())
282280
}
283281
}
284282
impl $crate::util::ser::Readable for $st {
285283
fn read<R: $crate::io::Read>(r: &mut R) -> Result<Self, $crate::ln::msgs::DecodeError> {
286284
$(let $field = $crate::util::ser::Readable::read(r)?;)*
287-
$(init_tlv_field_var!($tlvfield, $fieldty);)*
288-
decode_tlv_stream!(r, {$(($type, $tlvfield, $fieldty)),*});
285+
$($crate::init_tlv_field_var!($tlvfield, $fieldty);)*
286+
$crate::decode_tlv_stream!(r, {$(($type, $tlvfield, $fieldty)),*});
289287
Ok(Self {
290288
$($field),*,
291289
$($tlvfield),*

0 commit comments

Comments
 (0)