Skip to content

Commit 6e5d979

Browse files
authored
[server raw params]: fix debug implementation (#137)
* [server]: simply raw params impl Use debug implementation of `common::Params` instead of doing something similar that doesn't work properly. * [raw params]: derive `Debug` impl.
1 parent 1c86c71 commit 6e5d979

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/common/params.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ impl From<Params> for JsonValue {
7979
mod tests {
8080
use super::Params;
8181
use crate::common::{Error, ErrorCode, JsonValue};
82-
use serde_json;
8382

8483
#[test]
8584
fn params_deserialization() {

src/http/raw/params.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use alloc::string::String;
3030
use core::fmt;
3131

3232
/// Access to the parameters of a request.
33-
#[derive(Copy, Clone)]
33+
#[derive(Copy, Debug, Clone)]
3434
pub struct Params<'a> {
3535
/// Raw parameters of the request.
3636
params: &'a common::Params,
@@ -80,7 +80,7 @@ impl<'a> Params<'a> {
8080
}
8181

8282
impl<'a> IntoIterator for Params<'a> {
83-
type Item = (ParamKey<'a>, &'a common::JsonValue);
83+
type Item = Entry<'a>;
8484
type IntoIter = Iter<'a>;
8585

8686
fn into_iter(self) -> Self::IntoIter {
@@ -92,12 +92,6 @@ impl<'a> IntoIterator for Params<'a> {
9292
}
9393
}
9494

95-
impl<'a> fmt::Debug for Params<'a> {
96-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97-
f.debug_map().entries(self.into_iter()).finish()
98-
}
99-
}
100-
10195
impl<'a> AsRef<common::Params> for Params<'a> {
10296
fn as_ref(&self) -> &common::Params {
10397
self.params
@@ -146,14 +140,20 @@ enum IterInner<'a> {
146140
Array(std::slice::Iter<'a, serde_json::Value>),
147141
}
148142

143+
#[derive(Debug)]
144+
pub enum Entry<'a> {
145+
Value(&'a common::JsonValue),
146+
KeyValue(ParamKey<'a>, &'a common::JsonValue),
147+
}
148+
149149
impl<'a> Iterator for Iter<'a> {
150-
type Item = (ParamKey<'a>, &'a common::JsonValue);
150+
type Item = Entry<'a>;
151151

152152
fn next(&mut self) -> Option<Self::Item> {
153153
match &mut self.0 {
154154
IterInner::Empty => None,
155-
IterInner::Map(iter) => iter.next().map(|(k, v)| (ParamKey::String(&k[..]), v)),
156-
IterInner::Array(iter) => iter.next().map(|v| (ParamKey::String(""), v)),
155+
IterInner::Map(iter) => iter.next().map(|(k, v)| Entry::KeyValue(ParamKey::String(&k[..]), v)),
156+
IterInner::Array(iter) => iter.next().map(|v| Entry::Value(v)),
157157
}
158158
}
159159

src/ws/raw/params.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use alloc::string::String;
3030
use core::fmt;
3131

3232
/// Access to the parameters of a request.
33-
#[derive(Copy, Clone)]
33+
#[derive(Copy, Debug, Clone)]
3434
pub struct Params<'a> {
3535
/// Raw parameters of the request.
3636
params: &'a common::Params,
@@ -80,7 +80,7 @@ impl<'a> Params<'a> {
8080
}
8181

8282
impl<'a> IntoIterator for Params<'a> {
83-
type Item = (ParamKey<'a>, &'a common::JsonValue);
83+
type Item = Entry<'a>;
8484
type IntoIter = Iter<'a>;
8585

8686
fn into_iter(self) -> Self::IntoIter {
@@ -92,12 +92,6 @@ impl<'a> IntoIterator for Params<'a> {
9292
}
9393
}
9494

95-
impl<'a> fmt::Debug for Params<'a> {
96-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97-
f.debug_map().entries(self.into_iter()).finish()
98-
}
99-
}
100-
10195
impl<'a> AsRef<common::Params> for Params<'a> {
10296
fn as_ref(&self) -> &common::Params {
10397
self.params
@@ -146,14 +140,20 @@ enum IterInner<'a> {
146140
Array(std::slice::Iter<'a, serde_json::Value>),
147141
}
148142

143+
#[derive(Debug)]
144+
pub enum Entry<'a> {
145+
Value(&'a common::JsonValue),
146+
KeyValue(ParamKey<'a>, &'a common::JsonValue),
147+
}
148+
149149
impl<'a> Iterator for Iter<'a> {
150-
type Item = (ParamKey<'a>, &'a common::JsonValue);
150+
type Item = Entry<'a>;
151151

152152
fn next(&mut self) -> Option<Self::Item> {
153153
match &mut self.0 {
154154
IterInner::Empty => None,
155-
IterInner::Map(iter) => iter.next().map(|(k, v)| (ParamKey::String(&k[..]), v)),
156-
IterInner::Array(iter) => iter.next().map(|v| (ParamKey::String(""), v)),
155+
IterInner::Map(iter) => iter.next().map(|(k, v)| Entry::KeyValue(ParamKey::String(&k[..]), v)),
156+
IterInner::Array(iter) => iter.next().map(|v| Entry::Value(v)),
157157
}
158158
}
159159

0 commit comments

Comments
 (0)