use crate::FieldId;1use alloc::{borrow::Cow, format};2use thiserror::Error;34/// An error that occurs when cloning a type via [`PartialReflect::reflect_clone`].5///6/// [`PartialReflect::reflect_clone`]: crate::PartialReflect::reflect_clone7#[derive(Clone, Debug, Error, PartialEq, Eq)]8pub enum ReflectCloneError {9/// The type does not have a custom implementation for [`PartialReflect::reflect_clone`].10///11/// [`PartialReflect::reflect_clone`]: crate::PartialReflect::reflect_clone12#[error("`PartialReflect::reflect_clone` not implemented for `{type_path}`")]13NotImplemented {14/// The fully qualified path of the type that [`PartialReflect::reflect_clone`](crate::PartialReflect::reflect_clone) is not implemented for.15type_path: Cow<'static, str>,16},17/// The type cannot be cloned via [`PartialReflect::reflect_clone`].18///19/// This type should be returned when a type is intentionally opting out of reflection cloning.20///21/// [`PartialReflect::reflect_clone`]: crate::PartialReflect::reflect_clone22#[error("`{type_path}` cannot be made cloneable for `PartialReflect::reflect_clone`")]23NotCloneable {24/// The fully qualified path of the type that cannot be cloned via [`PartialReflect::reflect_clone`](crate::PartialReflect::reflect_clone).25type_path: Cow<'static, str>,26},27/// The field cannot be cloned via [`PartialReflect::reflect_clone`].28///29/// When [deriving `Reflect`], this usually means that a field marked with `#[reflect(ignore)]`30/// is missing a `#[reflect(clone)]` attribute.31///32/// This may be intentional if the field is not meant/able to be cloned.33///34/// [`PartialReflect::reflect_clone`]: crate::PartialReflect::reflect_clone35/// [deriving `Reflect`]: derive@crate::Reflect36#[error(37"field `{}` cannot be made cloneable for `PartialReflect::reflect_clone` (are you missing a `#[reflect(clone)]` attribute?)",38full_path(.field, .variant.as_deref(), .container_type_path)39)]40FieldNotCloneable {41/// Struct field or enum variant field which cannot be cloned.42field: FieldId,43/// Variant this field is part of if the container is an enum, otherwise [`None`].44variant: Option<Cow<'static, str>>,45/// Fully qualified path of the type containing this field.46container_type_path: Cow<'static, str>,47},48/// Could not downcast to the expected type.49///50/// Realistically this should only occur when a type has incorrectly implemented [`Reflect`].51///52/// [`Reflect`]: crate::Reflect53#[error("expected downcast to `{expected}`, but received `{received}`")]54FailedDowncast {55/// The fully qualified path of the type that was expected.56expected: Cow<'static, str>,57/// The fully qualified path of the type that was received.58received: Cow<'static, str>,59},60}6162fn full_path(63field: &FieldId,64variant: Option<&str>,65container_type_path: &str,66) -> alloc::string::String {67match variant {68Some(variant) => format!("{container_type_path}::{variant}::{field}"),69None => format!("{container_type_path}::{field}"),70}71}727374