Skip to content

Commit

Permalink
fill in the rest of the serde integration
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Dec 20, 2023
1 parent 825cb2c commit 6a3243e
Show file tree
Hide file tree
Showing 3 changed files with 523 additions and 835 deletions.
5 changes: 4 additions & 1 deletion buffer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ impl Error {
Error(ErrorKind::OutsideContainer { method })
}

pub(crate) fn invalid_value(reason: &'static str) -> Self {
/**
The given value is invalid.
*/
pub fn invalid_value(reason: &'static str) -> Self {
Error(ErrorKind::InvalidValue { reason })
}

Expand Down
47 changes: 29 additions & 18 deletions buffer/src/stream/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,35 @@ impl<'sval, S: Stream<'sval>> sval::Stream<'sval> for FlatStream<'sval, S> {
)
}

fn tag(
&mut self,
tag: Option<&sval::Tag>,
label: Option<&sval::Label>,
index: Option<&sval::Index>,
) -> sval::Result {
self.buffer_or_stream_with(
|buf| buf.tag(tag, label, index),
|stream| match stream.state {
State::Enum(ref mut stream) => {
let stream = stream.take().ok_or_else(|| {
Error::invalid_value(
"failed to stream an enum; the stream is already completed",
)
})?;

Ok(Some(stream.stream.tag(
tag.cloned(),
label.cloned(),
index.cloned(),
)?))
}
ref mut state => state.value_computed(&Tag(tag, label, index), |stream, _| {
stream.tag(tag.cloned(), label.cloned(), index.cloned())
}),
},
)
}

fn seq_begin(&mut self, num_entries: Option<usize>) -> sval::Result {
self.buffer_or_begin_with(
|buf| buf.seq_begin(num_entries),
Expand Down Expand Up @@ -532,24 +561,6 @@ impl<'sval, S: Stream<'sval>> sval::Stream<'sval> for FlatStream<'sval, S> {
)
}

fn tag(
&mut self,
tag: Option<&sval::Tag>,
label: Option<&sval::Label>,
index: Option<&sval::Index>,
) -> sval::Result {
self.buffer_or_stream_with(
|buf| buf.tag(tag, label, index),
|stream| {
stream
.state
.value_computed(&Tag(tag, label, index), |stream, _| {
stream.tag(tag.cloned(), label.cloned(), index.cloned())
})
},
)
}

fn null(&mut self) -> sval::Result {
self.buffer_or_stream_with(
|buf| buf.null(),
Expand Down
Loading

0 comments on commit 6a3243e

Please sign in to comment.