Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_reflect/src/serde/de/lists.rs
6600 views
1
use crate::{
2
serde::{de::registration_utils::try_get_registration, TypedReflectDeserializer},
3
DynamicList, ListInfo, TypeRegistry,
4
};
5
use core::{fmt, fmt::Formatter};
6
use serde::de::{SeqAccess, Visitor};
7
8
use super::ReflectDeserializerProcessor;
9
10
/// A [`Visitor`] for deserializing [`List`] values.
11
///
12
/// [`List`]: crate::List
13
pub(super) struct ListVisitor<'a, P> {
14
pub list_info: &'static ListInfo,
15
pub registry: &'a TypeRegistry,
16
pub processor: Option<&'a mut P>,
17
}
18
19
impl<'de, P: ReflectDeserializerProcessor> Visitor<'de> for ListVisitor<'_, P> {
20
type Value = DynamicList;
21
22
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
23
formatter.write_str("reflected list value")
24
}
25
26
fn visit_seq<V>(mut self, mut seq: V) -> Result<Self::Value, V::Error>
27
where
28
V: SeqAccess<'de>,
29
{
30
let mut list = DynamicList::default();
31
let registration = try_get_registration(self.list_info.item_ty(), self.registry)?;
32
while let Some(value) = seq.next_element_seed(TypedReflectDeserializer::new_internal(
33
registration,
34
self.registry,
35
self.processor.as_deref_mut(),
36
))? {
37
list.push_box(value);
38
}
39
Ok(list)
40
}
41
}
42
43