diff --git a/Cargo.toml b/Cargo.toml index 0e53c722..00cfc7b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,9 @@ edition = "2018" all-features = true rustdoc-args = ["--cfg", "docsrs"] +[lints.rust] +missing-debug-implementations = "warn" + [lib] name = "combine" path = "src/lib.rs" diff --git a/src/error.rs b/src/error.rs index f403521c..dd3b6d30 100644 --- a/src/error.rs +++ b/src/error.rs @@ -123,6 +123,7 @@ impl ErrorInfo<'_, Self, R> for u8 { } /// Newtype which constructs an `Info::Token` through `ErrorInfo` +#[derive(Debug)] pub struct Token(pub T); impl From> for Info { @@ -142,6 +143,7 @@ where } /// Newtype which constructs an `Info::Range` through `ErrorInfo` +#[derive(Debug)] pub struct Range(pub R); impl From> for Info { @@ -162,6 +164,7 @@ where /// Newtype which constructs an `Info::Static` through `ErrorInfo` /// A plain `&'static str` can also be used, this exists for consistency. +#[derive(Debug)] pub struct Static(&'static str); impl From for Info @@ -181,6 +184,7 @@ impl<'s, T, R> ErrorInfo<'s, T, R> for Static { } /// Newtype which constructs an `Info::Format` through `ErrorInfo` +#[derive(Debug)] pub struct Format(pub F) where F: fmt::Display; diff --git a/src/future_ext.rs b/src/future_ext.rs index f6168a34..69d49d64 100644 --- a/src/future_ext.rs +++ b/src/future_ext.rs @@ -4,6 +4,7 @@ use crate::lib::pin::Pin; use crate::lib::task::{Context, Poll}; // Replace usage of this with std::future::poll_fn once it stabilizes +#[derive(Debug)] pub struct PollFn { f: F, } diff --git a/src/lib.rs b/src/lib.rs index 04faedad..d81c494e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,7 +188,7 @@ clippy::inline_always, clippy::type_complexity, clippy::too_many_arguments, - clippy::match_like_matches_macro + clippy::match_like_matches_macro, )] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] @@ -427,6 +427,7 @@ macro_rules! combine_parser_impl { ) => { $(#[$derive])* + #[allow(missing_debug_implementations)] $struct_vis struct $type_name<$($type_params)*> where <$input_type as $crate::stream::StreamOnce>::Error: $crate::error::ParseError< diff --git a/src/parser/choice.rs b/src/parser/choice.rs index ef4e5a84..c5b8c83a 100644 --- a/src/parser/choice.rs +++ b/src/parser/choice.rs @@ -217,6 +217,7 @@ macro_rules! tuple_choice_parser { macro_rules! tuple_choice_parser_inner { ($partial_state: ident; $($id: ident)+) => { #[doc(hidden)] + #[allow(missing_debug_implementations)] pub enum $partial_state<$($id),+> { Peek, $( @@ -350,7 +351,7 @@ array_choice_parser!( 30 31 32 ); -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Choice

(P); impl Parser for Choice

@@ -557,7 +558,7 @@ where Choice(ps) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Or(Choice<(P1, P2)>); impl Parser for Or where @@ -630,7 +631,7 @@ where Or(choice((p1, p2))) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Optional

(P); impl Parser for Optional

where diff --git a/src/parser/combinator.rs b/src/parser/combinator.rs index e7a7ba19..3a420015 100644 --- a/src/parser/combinator.rs +++ b/src/parser/combinator.rs @@ -18,7 +18,7 @@ use alloc::{boxed::Box, string::String, vec::Vec}; #[cfg(feature = "alloc")] use crate::lib::any::Any; -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct NotFollowedBy

(P); impl Parser for NotFollowedBy

where @@ -86,7 +86,7 @@ where * TODO :: Rename `Try` to `Attempt` * Because this is public, it's name cannot be changed without also making a breaking change. */ -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Try

(P); impl Parser for Try

where @@ -164,7 +164,7 @@ where Try(p) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct LookAhead

(P); impl Parser for LookAhead

@@ -211,7 +211,7 @@ where LookAhead(p) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Map(P, F); impl Parser for Map where @@ -256,7 +256,7 @@ where Map(p, f) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct MapInput(P, F); impl Parser for MapInput where @@ -301,7 +301,7 @@ where MapInput(p, f) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct FlatMap(P, F); impl Parser for FlatMap where @@ -352,7 +352,7 @@ where FlatMap(p, f) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct AndThen(P, F); impl Parser for AndThen where @@ -423,7 +423,7 @@ where AndThen(p, f) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Recognize(P, PhantomData F>); impl Recognize { @@ -548,6 +548,7 @@ where Recognize(parser, PhantomData) } +#[derive(Debug)] pub enum Either { Left(L), Right(R), @@ -629,6 +630,7 @@ where } } +#[derive(Debug)] pub struct NoPartial

(P); impl Parser for NoPartial

@@ -672,7 +674,7 @@ where NoPartial(p) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Ignore

(P); impl Parser for Ignore

where @@ -718,11 +720,12 @@ where #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -#[derive(Default)] +#[derive(Debug, Default)] pub struct AnyPartialState(Option>); #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] +#[derive(Debug)] pub struct AnyPartialStateParser

(P); #[cfg(feature = "alloc")] @@ -821,11 +824,12 @@ where #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -#[derive(Default)] +#[derive(Debug, Default)] pub struct AnySendPartialState(Option>); #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] +#[derive(Debug)] pub struct AnySendPartialStateParser

(P); #[cfg(feature = "alloc")] @@ -924,11 +928,12 @@ where #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -#[derive(Default)] +#[derive(Debug, Default)] pub struct AnySendSyncPartialState(Option>); #[cfg(feature = "alloc")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] +#[derive(Debug)] pub struct AnySendSyncPartialStateParser

(P); #[cfg(feature = "alloc")] @@ -1023,7 +1028,7 @@ where AnySendSyncPartialStateParser(p) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Lazy

(P); impl Parser for Lazy

where @@ -1094,7 +1099,7 @@ where Lazy(p) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Factory(P, Option); impl Factory { @@ -1285,7 +1290,7 @@ where [ } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Opaque(F, PhantomData O>); impl Parser for Opaque where @@ -1421,6 +1426,7 @@ macro_rules! opaque { }; } +#[derive(Debug)] pub struct InputConverter where InputInner: Stream, @@ -1508,7 +1514,7 @@ where } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Spanned

(P); impl Parser for Spanned

where diff --git a/src/parser/error.rs b/src/parser/error.rs index 4ef6af17..66611f05 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -11,7 +11,7 @@ use crate::{ Parser, Stream, StreamOnce, }; -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Unexpected(E, PhantomData (I, T)>) where I: Stream; @@ -92,7 +92,7 @@ where Unexpected(message, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Message(P, S); impl Parser for Message where @@ -149,7 +149,7 @@ where Message(p, msg) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Expected(P, S); impl Parser for Expected where @@ -195,7 +195,7 @@ where Expected(p, info) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Silent

(P); impl Parser for Silent

where diff --git a/src/parser/function.rs b/src/parser/function.rs index 4d93b4a7..ed193621 100644 --- a/src/parser/function.rs +++ b/src/parser/function.rs @@ -19,7 +19,7 @@ impl<'a, Input: Stream, O> Parser } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct FnParser(F, PhantomData Input>); /// Wraps a function, turning it into a parser. @@ -93,7 +93,7 @@ where } } -#[derive(Copy)] +#[derive(Debug, Copy)] pub struct EnvParser where Input: Stream, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 17a88b7d..da55d521 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1147,7 +1147,7 @@ pub trait ParseMode: Copy { /// Internal API. May break without a semver bump #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct FirstMode; impl ParseMode for FirstMode { #[inline] @@ -1173,7 +1173,7 @@ impl ParseMode for FirstMode { /// Internal API. May break without a semver bump #[doc(hidden)] -#[derive(Copy, Clone, Default)] +#[derive(Debug, Copy, Clone, Default)] pub struct PartialMode { pub first: bool, } diff --git a/src/parser/range.rs b/src/parser/range.rs index 46353eb2..02758885 100644 --- a/src/parser/range.rs +++ b/src/parser/range.rs @@ -28,6 +28,7 @@ use crate::stream::{ use crate::Parser; +#[derive(Debug)] pub struct Range(Input::Range) where Input: RangeStream; @@ -146,7 +147,7 @@ where } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct RecognizeWithValue

(P); impl Parser for RecognizeWithValue

@@ -256,6 +257,7 @@ where Range(i) } +#[derive(Debug)] pub struct Take(usize, PhantomData); impl Parser for Take where @@ -300,6 +302,7 @@ where Take(n, PhantomData) } +#[derive(Debug)] pub struct TakeWhile(F, PhantomData Input>); impl Parser for TakeWhile where @@ -358,6 +361,7 @@ where TakeWhile(f, PhantomData) } +#[derive(Debug)] pub struct TakeWhile1(F, PhantomData Input>); impl Parser for TakeWhile1 where @@ -416,6 +420,7 @@ where TakeWhile1(f, PhantomData) } +#[derive(Debug)] pub struct TakeUntilRange(Input::Range) where Input: RangeStream; @@ -548,6 +553,7 @@ impl From> for TakeRange { } } +#[derive(Debug)] pub struct TakeFn { searcher: F, _marker: PhantomData, diff --git a/src/parser/regex.rs b/src/parser/regex.rs index 6e47e446..a904f300 100644 --- a/src/parser/regex.rs +++ b/src/parser/regex.rs @@ -218,6 +218,7 @@ mod regex { } } +#[derive(Debug)] pub struct Match(R, PhantomData); impl<'a, Input, R> Parser for Match @@ -273,7 +274,7 @@ where Match(regex, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Find(R, PhantomData Input>); impl<'a, Input, R> Parser for Find @@ -334,7 +335,7 @@ where Find(regex, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct FindMany(R, PhantomData (Input, F)>); impl<'a, Input, F, R> Parser for FindMany @@ -392,7 +393,7 @@ where FindMany(regex, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Captures(R, PhantomData (Input, F)>); impl<'a, Input, F, R> Parser for Captures @@ -460,7 +461,7 @@ where Captures(regex, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct CapturesMany(R, PhantomData (Input, F, G)>); impl<'a, Input, F, G, R> Parser for CapturesMany diff --git a/src/parser/repeat.rs b/src/parser/repeat.rs index 27543c3e..594cab1f 100644 --- a/src/parser/repeat.rs +++ b/src/parser/repeat.rs @@ -72,7 +72,7 @@ parser! { } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct CountMinMax { parser: P, min: usize, @@ -243,6 +243,29 @@ where mode: M, } +use std::fmt; + +impl<'a, Input, P, S, M> fmt::Debug for Iter<'a, Input, P, S, M> +where + Input: Stream, + P: Parser + fmt::Debug, + S: fmt::Debug, + M: fmt::Debug, + ::Error: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Iter") + .field("parser", &self.parser) + .field("input", &format_args!("")) + .field("committed", &self.committed) + .field("state", &self.state) + .field("partial_state", &self.partial_state) + .field("mode", &self.mode) + .finish() + } +} + +#[derive(Debug)] enum State { Ok, PeekErr(E), @@ -374,7 +397,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Many(P, PhantomData); impl Parser for Many @@ -447,7 +470,7 @@ where Many(p, PhantomData) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Many1(P, PhantomData F>); impl Parser for Many1 where @@ -535,7 +558,7 @@ where Many1(p, PhantomData) } -#[derive(Clone)] +#[derive(Debug, Clone)] #[doc(hidden)] // FIXME Should not be public pub struct Sink; @@ -609,7 +632,7 @@ where [ } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct SepBy { parser: P, separator: S, @@ -684,7 +707,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct SepBy1 { parser: P, separator: S, @@ -791,7 +814,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct SepEndBy { parser: P, separator: S, @@ -865,7 +888,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct SepEndBy1 { parser: P, separator: S, @@ -977,7 +1000,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Chainl1(P, Op); impl Parser for Chainl1 where @@ -1067,7 +1090,7 @@ where Chainl1(parser, op) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Chainr1(P, Op); impl Parser for Chainr1 where @@ -1139,7 +1162,7 @@ where Chainr1(parser, op) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct TakeUntil { end: P, _marker: PhantomData F>, @@ -1261,7 +1284,7 @@ parser! { } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct RepeatUntil { parser: P, end: E, @@ -1373,9 +1396,10 @@ parser! { } } -#[derive(Default)] +#[derive(Debug, Default)] pub struct EscapedState(PhantomData<(T, U)>); +#[derive(Debug)] pub struct Escaped { parser: P, escape: I, @@ -1487,6 +1511,7 @@ where } } +#[derive(Debug)] pub struct Iterate { parser: P, iterable: I, diff --git a/src/parser/sequence.rs b/src/parser/sequence.rs index 8e0ecc9c..fab901c5 100644 --- a/src/parser/sequence.rs +++ b/src/parser/sequence.rs @@ -21,6 +21,7 @@ macro_rules! count { } #[doc(hidden)] +#[derive(Debug)] pub struct SequenceState { pub value: Option, pub state: U, @@ -86,7 +87,7 @@ where macro_rules! tuple_parser { ($partial_state: ident; $h: ident $(, $id: ident)*) => { #[allow(non_snake_case)] - #[derive(Default)] + #[derive(Debug, Default)] pub struct $partial_state < $h $(, $id )* > { pub $h: $h, $( @@ -505,7 +506,7 @@ macro_rules! struct_parser { } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct With((Ignore, P2)); impl Parser for With where @@ -553,7 +554,7 @@ where With((ignore(p1), p2)) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Skip((P1, Ignore)); impl Parser for Skip where @@ -591,7 +592,7 @@ where } parser! { - #[derive(Copy, Clone)] + #[derive(Debug, Copy, Clone)] pub struct Between; type PartialState = P::Output> as Parser>::PartialState; /// Parses `open` followed by `parser` followed by `close`. @@ -623,7 +624,7 @@ where [ } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Then(P, F); impl Parser for Then where @@ -713,7 +714,7 @@ where Then(p, f) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ThenPartial(P, F); impl Parser for ThenPartial where @@ -810,7 +811,7 @@ mod tests { } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ThenRef(P, F); impl Parser for ThenRef where diff --git a/src/parser/token.rs b/src/parser/token.rs index fe414210..bd48dac0 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -11,7 +11,7 @@ use crate::{ Parser, }; -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Any(PhantomData Input>); impl Parser for Any @@ -48,7 +48,7 @@ where Any(PhantomData) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Satisfy { predicate: P, _marker: PhantomData, @@ -112,7 +112,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct SatisfyMap { predicate: P, _marker: PhantomData, @@ -166,7 +166,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Token where Input: Stream, @@ -216,7 +216,7 @@ where } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Tokens where Input: Stream, @@ -321,7 +321,7 @@ where } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct TokensCmp where Input: Stream, @@ -420,7 +420,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Position where Input: Stream, @@ -465,7 +465,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct OneOf where Input: Stream, @@ -518,7 +518,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct NoneOf where Input: Stream, @@ -576,7 +576,7 @@ where } } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Value(T, PhantomData Input>); impl Parser for Value where @@ -611,7 +611,7 @@ where Value(v, PhantomData) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Produce(F, PhantomData Input>); impl Parser for Produce where @@ -647,7 +647,7 @@ where Produce(f, PhantomData) } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Eof(PhantomData); impl Parser for Eof where diff --git a/src/stream/buf_reader.rs b/src/stream/buf_reader.rs index e6c27629..6cb8996d 100644 --- a/src/stream/buf_reader.rs +++ b/src/stream/buf_reader.rs @@ -179,7 +179,7 @@ where } /// Marker used by `Decoder` for an internal buffer -#[derive(Default)] +#[derive(Debug, Default)] pub struct Buffer(pub(crate) BytesMut); impl sealed::Sealed for Buffer {} @@ -324,7 +324,7 @@ fn tokio_read_buf( } /// Marker used by `Decoder` for an external buffer -#[derive(Default)] +#[derive(Debug, Default)] pub struct Bufferless; impl sealed::Sealed for Bufferless {} diff --git a/src/stream/decoder.rs b/src/stream/decoder.rs index ad034f87..e95ccc4e 100644 --- a/src/stream/decoder.rs +++ b/src/stream/decoder.rs @@ -48,7 +48,7 @@ impl fmt::Display for Error { } } -#[derive(Default)] +#[derive(Debug, Default)] /// Used together with the `decode!` macro pub struct Decoder { position: P, diff --git a/src/stream/read.rs b/src/stream/read.rs index 6fa13b01..57fb9169 100644 --- a/src/stream/read.rs +++ b/src/stream/read.rs @@ -154,6 +154,7 @@ where } } +#[derive(Debug)] pub struct Stream { bytes: Bytes, }