/rust/registry/src/index.crates.io-6f17d22bba15001f/serde-content-0.1.2/src/ser/struct.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::ser::Value; |
2 | | use crate::Data; |
3 | | use crate::Error; |
4 | | use crate::Serializer; |
5 | | use alloc::borrow::Cow; |
6 | | use alloc::boxed::Box; |
7 | | use serde::ser; |
8 | | use serde::ser::SerializeMap; |
9 | | use serde::ser::SerializeStruct; |
10 | | use serde::ser::SerializeTupleStruct; |
11 | | |
12 | | use super::to_static_str; |
13 | | |
14 | | pub struct Struct<'a> { |
15 | | r#struct: crate::Struct<'a>, |
16 | | human_readable: bool, |
17 | | } |
18 | | |
19 | | impl<'a> Struct<'a> { |
20 | 0 | pub(super) const fn new(r#struct: crate::Struct<'a>, human_readable: bool) -> Self { |
21 | 0 | Self { |
22 | 0 | r#struct, |
23 | 0 | human_readable, |
24 | 0 | } |
25 | 0 | } |
26 | | } |
27 | | |
28 | | impl ser::Serialize for crate::Struct<'_> { |
29 | 0 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
30 | 0 | where |
31 | 0 | S: ser::Serializer, |
32 | 0 | { |
33 | 0 | match &self.data { |
34 | 0 | Data::Unit => match &self.name { |
35 | 0 | Cow::Borrowed(name) => serializer.serialize_unit_struct(name), |
36 | 0 | Cow::Owned(_) => serializer.serialize_unit(), |
37 | | }, |
38 | 0 | Data::NewType { value } => match &self.name { |
39 | 0 | Cow::Borrowed(name) => serializer.serialize_newtype_struct(name, value), |
40 | 0 | Cow::Owned(_) => value.serialize(serializer), |
41 | | }, |
42 | 0 | Data::Tuple { values } => match &self.name { |
43 | 0 | Cow::Borrowed(name) => { |
44 | 0 | let mut tup = serializer.serialize_tuple_struct(name, values.len())?; |
45 | 0 | for value in values { |
46 | 0 | tup.serialize_field(value)?; |
47 | | } |
48 | 0 | tup.end() |
49 | | } |
50 | 0 | Cow::Owned(_) => values.serialize(serializer), |
51 | | }, |
52 | 0 | Data::Struct { fields } => match &self.name { |
53 | 0 | Cow::Borrowed(name) => { |
54 | 0 | let mut map = serializer.serialize_struct(name, fields.len())?; |
55 | 0 | for (key, value) in fields { |
56 | 0 | let key = to_static_str(key)?; |
57 | 0 | map.serialize_field(key, value)?; |
58 | | } |
59 | 0 | map.end() |
60 | | } |
61 | | Cow::Owned(_) => { |
62 | 0 | let mut map = serializer.serialize_map(Some(fields.len()))?; |
63 | 0 | for (key, value) in fields { |
64 | 0 | map.serialize_entry(key, value)?; |
65 | | } |
66 | 0 | map.end() |
67 | | } |
68 | | }, |
69 | | } |
70 | 0 | } |
71 | | } |
72 | | |
73 | | impl<'a> ser::SerializeStruct for Struct<'a> { |
74 | | type Ok = Value<'a>; |
75 | | type Error = Error; |
76 | | |
77 | 0 | fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Error> |
78 | 0 | where |
79 | 0 | T: ?Sized + ser::Serialize, |
80 | 0 | { |
81 | 0 | if let Data::Struct { fields } = &mut self.r#struct.data { |
82 | 0 | let value = value.serialize(Serializer::with_human_readable(self.human_readable))?; |
83 | 0 | fields.push((Cow::Borrowed(key), value)); |
84 | 0 | } |
85 | 0 | Ok(()) |
86 | 0 | } Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<&str> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<()> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<geo_types::geometry::line_string::LineString>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::api::method::Method>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::sql::ident::Ident>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::iam::entities::roles::Role>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::sql::value::value::Value>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::sql::statements::define::api::ApiAction>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<(surrealdb_core::sql::ident::Ident, surrealdb_core::sql::kind::Kind)>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::vec::Vec<(surrealdb_core::sql::value::value::Value, surrealdb_core::sql::value::value::Value)>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<core::option::Option<surrealdb_core::sql::changefeed::ChangeFeed>>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<core::option::Option<surrealdb_core::sql::strand::Strand>>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<alloc::vec::Vec<surrealdb_core::sql::filter::Filter>>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<alloc::vec::Vec<surrealdb_core::sql::tokenizer::Tokenizer>>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<alloc::string::String>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::api::middleware::RequestMiddleware>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::iam::auth::Auth>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::changefeed::ChangeFeed>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::permission::Permission>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::permission::Permissions>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::table_type::TableType>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::access_type::BearerAccess>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::access_type::JwtAccessIssue>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::base::Base>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::cond::Cond>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::data::Data>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::kind::Kind>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::view::View>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::with::With>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::fetch::Fetchs>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::field::Fields>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::group::Groups>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::ident::Ident>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::idiom::Idiom>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::idiom::Idioms>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::limit::Limit>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::order::Ordering>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::split::Splits>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::start::Start>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::table::Table>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::output::Output>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::strand::Strand>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::explain::Explain>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::timeout::Timeout>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::version::Version>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::duration::Duration>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::reference::Reference>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::value::value::Value>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<surrealdb_core::sql::statements::define::config::api::ApiConfig>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<bool>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::option::Option<u32>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::ops::range::Bound<surrealdb_core::sql::id::Id>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::ops::range::Bound<surrealdb_core::sql::value::value::Value>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<uuid::Uuid> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<alloc::string::String> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<core::time::Duration> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<geo_types::geometry::line_string::LineString> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::dbs::notification::Action> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::dbs::response::Status> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::permission::Permission> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::permission::Permissions> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::table_type::TableType> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access_type::AccessType> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access_type::JwtAccessVerify> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access_type::BearerAccessType> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access_type::BearerAccessSubject> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access_type::JwtAccess> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::id::Id> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::dir::Dir> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::base::Base> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::data::Data> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::user::UserDuration> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::uuid::Uuid> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::block::Block> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::field::Fields> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::ident::Ident> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::idiom::Idiom> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::idiom::Idioms> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::index::VectorType> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::index::Index> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::index::Distance> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::param::Param> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::table::Tables> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::thing::Thing> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::access::AccessDuration> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::number::Number> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::scoring::Scoring> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::duration::Duration> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::algorithm::Algorithm> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::reference::ReferenceDeleteStrategy> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::statements::show::ShowSince> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::statements::access::Subject> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::value::value::Value> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::value::value::Values> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::iam::entities::resources::actor::Actor> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::iam::entities::resources::resource::Resource> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::statements::define::config::ConfigInner> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::statements::define::config::graphql::TablesConfig> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<surrealdb_core::sql::statements::define::config::graphql::FunctionsConfig> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<bool> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<f64> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<str> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<u8> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<u32> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<u16> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<u64> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeStruct>::serialize_field::<_> |
87 | | |
88 | 0 | fn end(self) -> Result<Self::Ok, Error> { |
89 | 0 | Ok(Value::Struct(Box::new(self.r#struct))) |
90 | 0 | } |
91 | | } |
92 | | |
93 | | impl<'a> ser::SerializeTupleStruct for Struct<'a> { |
94 | | type Ok = Value<'a>; |
95 | | type Error = Error; |
96 | | |
97 | 0 | fn serialize_field<T>(&mut self, value: &T) -> Result<(), Error> |
98 | 0 | where |
99 | 0 | T: ?Sized + ser::Serialize, |
100 | 0 | { |
101 | 0 | if let Data::Tuple { values } = &mut self.r#struct.data { |
102 | 0 | let value = value.serialize(Serializer::with_human_readable(self.human_readable))?; |
103 | 0 | values.push(value); |
104 | 0 | } |
105 | 0 | Ok(()) |
106 | 0 | } Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<alloc::vec::Vec<surrealdb_core::sql::field::Field>> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<alloc::string::String> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<surrealdb_core::sql::kind::Kind> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<surrealdb_core::sql::value::value::Value> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<surrealdb_core::iam::entities::resources::level::Level> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<surrealdb_core::iam::entities::resources::resource::ResourceKind> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<bool> Unexecuted instantiation: <serde_content::ser::struct::Struct as serde::ser::SerializeTupleStruct>::serialize_field::<_> |
107 | | |
108 | 0 | fn end(self) -> Result<Self::Ok, Error> { |
109 | 0 | Ok(Value::Struct(Box::new(self.r#struct))) |
110 | 0 | } |
111 | | } |