bevy_reflect/serde/de/
registration_utils.rs

1use crate::{serde::de::error_utils::make_custom_error, Type, TypeRegistration, TypeRegistry};
2use serde::de::Error;
3
4/// Attempts to find the [`TypeRegistration`] for a given [type].
5///
6/// [type]: Type
7pub(super) fn try_get_registration<E: Error>(
8    ty: Type,
9    registry: &TypeRegistry,
10) -> Result<&TypeRegistration, E> {
11    let registration = registry.get(ty.id()).ok_or_else(|| {
12        make_custom_error(format_args!("no registration found for type `{ty:?}`"))
13    })?;
14    Ok(registration)
15}