diff --git a/radix-engine-interface/src/object_modules/metadata/models/mod.rs b/radix-engine-interface/src/object_modules/metadata/models/mod.rs index 7ff54b8bb7d..278eabce066 100644 --- a/radix-engine-interface/src/object_modules/metadata/models/mod.rs +++ b/radix-engine-interface/src/object_modules/metadata/models/mod.rs @@ -22,7 +22,7 @@ use sbor::SborEnum; #[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)] -#[sbor(categorize_types = "U, O")] +#[sbor(categorize_types = "U; O")] pub enum GenericMetadataValue { #[sbor(discriminator(METADATA_VALUE_STRING_DISCRIMINATOR))] String(String), diff --git a/sbor-derive-common/src/decode.rs b/sbor-derive-common/src/decode.rs index e8283993e4f..c3b26d0fb71 100644 --- a/sbor-derive-common/src/decode.rs +++ b/sbor-derive-common/src/decode.rs @@ -415,7 +415,7 @@ mod tests { #[test] fn test_decode_struct_with_generic_params() { - let input = TokenStream::from_str("#[sbor(categorize_types = \"T1, T2\")] struct Test<'a, S, T1, T2> {a: &'a u32, b: S, c: Vec, d: Vec}").unwrap(); + let input = TokenStream::from_str("#[sbor(categorize_types = \"T1; T2\")] struct Test<'a, S, T1, T2> {a: &'a u32, b: S, c: Vec, d: Vec}").unwrap(); let output = handle_decode(input, None).unwrap(); assert_code_eq( diff --git a/sbor-derive-common/src/utils.rs b/sbor-derive-common/src/utils.rs index 1cb5bce8181..63f97fbc975 100644 --- a/sbor-derive-common/src/utils.rs +++ b/sbor-derive-common/src/utils.rs @@ -654,11 +654,11 @@ pub fn parse_single_type(source_string: &LitStr) -> syn::Result { source_string.parse() } -pub fn parse_comma_separated_types(source_string: &LitStr) -> syn::Result> { +pub fn parse_semicolon_separated_types(source_string: &LitStr) -> syn::Result> { let span = source_string.span(); source_string .value() - .split(',') + .split(';') .map(|s| s.trim().to_owned()) .filter(|f| f.len() > 0) .map(|s| LitStr::new(&s, span).parse()) @@ -670,27 +670,29 @@ pub fn parse_comma_separated_types(source_string: &LitStr) -> syn::Result MyStruct(T::MyAssociatedType)` should use `#[sbor(child_types = "T::MyAssociatedType")]`. fn get_child_types(attributes: &[Attribute], existing_generics: &Generics) -> Result> { - let Some(comma_separated_types) = get_sbor_attribute_string_value(attributes, "child_types")? + let Some(child_types_attribute_value) = + get_sbor_attribute_string_value(attributes, "child_types")? else { // If no explicit child_types list is set, we use all pre-existing generic type parameters. - // This means (eg) that they all have to implement the relevant trait (Encode/Decode/Describe) + // This means (e.g.) that they all have to implement the relevant trait (Encode/Decode/Describe) // This is essentially what derived traits such as Clone do: https://github.com/rust-lang/rust/issues/26925 // It's not perfect - but it's typically good enough! return Ok(get_generic_types(existing_generics)); }; - parse_comma_separated_types(&comma_separated_types) + parse_semicolon_separated_types(&child_types_attribute_value) } fn get_types_requiring_categorize_bound_for_encode_and_decode( attributes: &[Attribute], ) -> Result> { - let comma_separated_types = get_sbor_attribute_string_value(attributes, "categorize_types")?; + let categorize_types_attribute_value = + get_sbor_attribute_string_value(attributes, "categorize_types")?; // We need to work out what the default behaviour is if no `categorize_types` are provided. // // Now, for a given generic parameter T, we have a few cases how it appears in the type: @@ -718,8 +720,8 @@ fn get_types_requiring_categorize_bound_for_encode_and_decode( // We used to use (C), but we have now switched to (A) because we believe it to be clearer, on balance. // Also, providing #[sbor(categorize_types = "T")] feels more explicit sometimes than confusingly having // to add #[sbor(categorize_types = "")] sometimes. - if let Some(comma_separated_types) = comma_separated_types { - parse_comma_separated_types(&comma_separated_types) + if let Some(categorize_types_attribute_value) = categorize_types_attribute_value { + parse_semicolon_separated_types(&categorize_types_attribute_value) } else { Ok(vec![]) } diff --git a/sbor-tests/tests/schema.rs b/sbor-tests/tests/schema.rs index 830f7a53076..9f86b9cd24c 100644 --- a/sbor-tests/tests/schema.rs +++ b/sbor-tests/tests/schema.rs @@ -17,7 +17,7 @@ pub struct BasicSample { } #[derive(Sbor)] -#[sbor(categorize_types = "S, T")] +#[sbor(categorize_types = "S; T")] pub struct AdvancedSample { pub a: (), pub b: u32, diff --git a/sbor/src/schema/schema.rs b/sbor/src/schema/schema.rs index 2d2489ce50c..300efc13fb4 100644 --- a/sbor/src/schema/schema.rs +++ b/sbor/src/schema/schema.rs @@ -3,7 +3,7 @@ use crate::*; define_single_versioned!( #[derive(Debug, Clone, PartialEq, Eq, Sbor)] - #[sbor(child_types = "S::CustomLocalTypeKind, S::CustomTypeValidation")] + #[sbor(child_types = "S::CustomLocalTypeKind; S::CustomTypeValidation")] pub VersionedSchema(SchemaVersions) => Schema = SchemaV1:: ); @@ -32,7 +32,7 @@ impl Default for VersionedSchema { /// A serializable record of the schema of a single type. /// Intended for historical backwards compatibility checking of a single type. #[derive(Debug, Clone, Sbor)] -#[sbor(child_types = "S::CustomLocalTypeKind, S::CustomTypeValidation")] +#[sbor(child_types = "S::CustomLocalTypeKind; S::CustomTypeValidation")] pub struct SingleTypeSchema { pub schema: VersionedSchema, pub type_id: LocalTypeId, @@ -58,7 +58,7 @@ impl SingleTypeSchema { /// /// For example, traits, or blueprint interfaces. #[derive(Debug, Clone, Sbor)] -#[sbor(child_types = "S::CustomLocalTypeKind, S::CustomTypeValidation")] +#[sbor(child_types = "S::CustomLocalTypeKind; S::CustomTypeValidation")] pub struct TypeCollectionSchema { pub schema: VersionedSchema, pub type_ids: IndexMap, @@ -84,7 +84,7 @@ impl TypeCollectionSchema { // * Via TypeKind, S::CustomLocalTypeKind gets embedded // * Via TypeValidation, S::CustomTypeValidation gets embedded // So theses are the child types which need to be registered with the sbor macro for it to compile -#[sbor(child_types = "S::CustomLocalTypeKind, S::CustomTypeValidation")] +#[sbor(child_types = "S::CustomLocalTypeKind; S::CustomTypeValidation")] pub struct SchemaV1 { pub type_kinds: Vec>, pub type_metadata: Vec, // TODO: reconsider adding type hash when it's ready! diff --git a/sbor/src/schema/type_data/type_kind.rs b/sbor/src/schema/type_data/type_kind.rs index 746fc962555..0d7869b3cbb 100644 --- a/sbor/src/schema/type_data/type_kind.rs +++ b/sbor/src/schema/type_data/type_kind.rs @@ -8,7 +8,7 @@ pub type AggregatorTypeKind = /// A schema for the values that a codec can decode / views as valid #[derive(Debug, Clone, PartialEq, Eq, Sbor)] -#[sbor(child_types = "T, L", categorize_types = "L")] +#[sbor(child_types = "T; L", categorize_types = "L")] pub enum TypeKind, L: SchemaTypeLink> { Any,