bevy_reflect/serde/de/
registration_utils.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::{serde::de::error_utils::make_custom_error, Type, TypeRegistration, TypeRegistry};
use serde::de::Error;

/// Attempts to find the [`TypeRegistration`] for a given [type].
///
/// [type]: Type
pub(super) fn try_get_registration<E: Error>(
    ty: Type,
    registry: &TypeRegistry,
) -> Result<&TypeRegistration, E> {
    let registration = registry.get(ty.id()).ok_or_else(|| {
        make_custom_error(format_args!("no registration found for type `{ty:?}`"))
    })?;
    Ok(registration)
}