facet_json/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![warn(clippy::std_instead_of_core)]
4#![warn(clippy::std_instead_of_alloc)]
5#![deny(unsafe_code)]
6#![doc = include_str!("../README.md")]
7
8#[cfg(feature = "alloc")]
9extern crate alloc;
10
11#[cfg(not(feature = "alloc"))]
12compile_error!("feature `alloc` is required");
13
14mod deserialize;
15pub use deserialize::*;
16
17#[cfg(feature = "std")]
18mod serialize;
19#[cfg(feature = "std")]
20pub use serialize::*;
21
22#[cfg(feature = "std")]
23fn variant_is_transparent(variant: &facet_core::Variant) -> bool {
24    variant.data.kind == facet_core::StructKind::Tuple && variant.data.fields.len() == 1
25}
26
27#[cfg(feature = "std")]
28trait First<T> {
29    fn with_first(self) -> impl Iterator<Item = (bool, T)>;
30}
31
32#[cfg(feature = "std")]
33impl<Iter, T> First<T> for Iter
34where
35    Iter: Iterator<Item = T>,
36{
37    fn with_first(self) -> impl Iterator<Item = (bool, T)> {
38        self.enumerate().map(|(idx, elem)| (idx == 0, elem))
39    }
40}