Path: blob/main/crates/bevy_reflect/src/serde/de/lists.rs
6600 views
use crate::{1serde::{de::registration_utils::try_get_registration, TypedReflectDeserializer},2DynamicList, ListInfo, TypeRegistry,3};4use core::{fmt, fmt::Formatter};5use serde::de::{SeqAccess, Visitor};67use super::ReflectDeserializerProcessor;89/// A [`Visitor`] for deserializing [`List`] values.10///11/// [`List`]: crate::List12pub(super) struct ListVisitor<'a, P> {13pub list_info: &'static ListInfo,14pub registry: &'a TypeRegistry,15pub processor: Option<&'a mut P>,16}1718impl<'de, P: ReflectDeserializerProcessor> Visitor<'de> for ListVisitor<'_, P> {19type Value = DynamicList;2021fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {22formatter.write_str("reflected list value")23}2425fn visit_seq<V>(mut self, mut seq: V) -> Result<Self::Value, V::Error>26where27V: SeqAccess<'de>,28{29let mut list = DynamicList::default();30let registration = try_get_registration(self.list_info.item_ty(), self.registry)?;31while let Some(value) = seq.next_element_seed(TypedReflectDeserializer::new_internal(32registration,33self.registry,34self.processor.as_deref_mut(),35))? {36list.push_box(value);37}38Ok(list)39}40}414243