Fix error message for the Component
macro's component
storage
attribute. (#3534)
# Objective Fixes the error message for the `component` attribute when users use the wrong literals.
This commit is contained in:
parent
a6d3cd92fe
commit
d44c3cd150
@ -43,6 +43,10 @@ enum StorageTy {
|
|||||||
SparseSet,
|
SparseSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// values for `storage` attribute
|
||||||
|
const TABLE: &str = "Table";
|
||||||
|
const SPARSE_SET: &str = "SparseSet";
|
||||||
|
|
||||||
fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
|
fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
|
||||||
let meta_items = bevy_macro_utils::parse_attrs(ast, COMPONENT)?;
|
let meta_items = bevy_macro_utils::parse_attrs(ast, COMPONENT)?;
|
||||||
|
|
||||||
@ -58,14 +62,14 @@ fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
|
|||||||
match meta {
|
match meta {
|
||||||
Meta(NameValue(m)) if m.path == STORAGE => {
|
Meta(NameValue(m)) if m.path == STORAGE => {
|
||||||
attrs.storage = match get_lit_str(STORAGE, &m.lit)?.value().as_str() {
|
attrs.storage = match get_lit_str(STORAGE, &m.lit)?.value().as_str() {
|
||||||
"Table" => StorageTy::Table,
|
TABLE => StorageTy::Table,
|
||||||
"SparseSet" => StorageTy::SparseSet,
|
SPARSE_SET => StorageTy::SparseSet,
|
||||||
s => {
|
s => {
|
||||||
return Err(Error::new_spanned(
|
return Err(Error::new_spanned(
|
||||||
m.lit,
|
m.lit,
|
||||||
format!(
|
format!(
|
||||||
"Invalid storage type `{}`, expected 'table' or 'sparse'.",
|
"Invalid storage type `{}`, expected '{}' or '{}'.",
|
||||||
s
|
s, TABLE, SPARSE_SET
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user