Skip to content

Commit

Permalink
some API adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Jan 2, 2024
1 parent 9993a0e commit 1b0ae42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
4 changes: 2 additions & 2 deletions nested/src/flat_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ impl<'sval, S: StreamEnum<'sval>> Stream<'sval> for FlatStreamEnum<S> {
}

fn seq_begin(self, _: Option<usize>) -> Result<Self::Seq> {
Ok(Unsupported::default())
Err(Error::invalid_value("sequences are unsupported"))
}

fn map_begin(self, _: Option<usize>) -> Result<Self::Map> {
Ok(Unsupported::default())
Err(Error::invalid_value("maps are unsupported"))
}

fn tuple_begin(
Expand Down
57 changes: 25 additions & 32 deletions nested/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use self::flat::FlatStream;
/**
Stream a value through a stream.
*/
pub fn stream<'sval, S: Stream<'sval>>(stream: S, value: impl ValueRef<'sval>) -> Result<S::Ok> {
pub fn stream<'sval, S: Stream<'sval>>(
stream: S,
value: impl ValueRef<'sval>,
) -> Result<S::Ok> {
stream.value(value)
}

Expand Down Expand Up @@ -684,13 +687,10 @@ pub trait StreamEnum<'sval> {
/**
A placeholder for a kind of value that isn't supported by a particular stream.
*/
pub struct Unsupported<Ok>(PhantomData<Result<Ok, Error>>);
pub struct Unsupported<Ok>(Void, PhantomData<Result<Ok, Error>>);

impl<Ok> Default for Unsupported<Ok> {
fn default() -> Self {
Unsupported(PhantomData)
}
}
// Ensure `Unsupported` can't be constructed
enum Void {}

impl<'sval, Ok> Stream<'sval> for Unsupported<Ok> {
type Ok = Ok;
Expand Down Expand Up @@ -1085,10 +1085,7 @@ pub mod default_stream {
}

impl<'a> sval::Value for Tag<'a> {
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut S,
) -> sval::Result {
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(&'sval self, stream: &mut S) -> sval::Result {
self.stream_ref(stream)
}
}
Expand All @@ -1114,15 +1111,7 @@ pub mod default_stream {
}
}

stream.tagged(
tag.clone(),
label.clone(),
index,
Tag {
tag: tag.as_ref(),
label: label.as_ref(),
},
)
stream.tagged(tag.clone(), label.clone(), index, Tag { tag: tag.as_ref(), label: label.as_ref() })
}

/**
Expand Down Expand Up @@ -1423,14 +1412,12 @@ mod tests {
}

assert_eq!(
Value::Tag(
Tag::new(
Some(sval::tags::RUST_OPTION_NONE),
Some(sval::Label::new("None")),
Some(sval::Index::new(0))
)
.unwrap()
),
Value::Tag(Tag::new(
Some(sval::tags::RUST_OPTION_NONE),
Some(sval::Label::new("None")),
Some(sval::Index::new(0))
)
.unwrap()),
ToValue::default().value_ref(&None::<Inner>).unwrap()
);

Expand All @@ -1443,16 +1430,22 @@ mod tests {
)
.unwrap(),
value: Box::new(Value::Record(Record {
tag: Tag::new(None, Some(sval::Label::new("Inner")), None,).unwrap(),
tag: Tag::new(
None,
Some(sval::Label::new("Inner")),
None,
)
.unwrap(),
entries: vec![
(sval::Label::new("a"), Value::I64(42)),
(sval::Label::new("b"), Value::Bool(true)),
]
}))
}),
ToValue::default()
.value_ref(&Some(Inner { a: 42, b: true }))
.unwrap()
ToValue::default().value_ref(&Some(Inner {
a: 42,
b: true,
})).unwrap()
);
}

Expand Down

0 comments on commit 1b0ae42

Please sign in to comment.