Azure / Azure/typespec-rust

Compilation error: the trait bound `serde::Serializer` is not satisfied for unions

Open
#923 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
7
Forks
11
Avg merge
2d 5h
Merged PRs (30d)
5

Description

This affects `specification/datafactory/resource-manager/Microsoft.DataFactory/DataFactory`

The errors are
```
error[E0277]: the trait bound `&std::option::Option: serde::Serializer` is not satisfied
--> spec\rmDataFactory\src\generated\models\unions_serde.rs:1483:17
|
1476 | } => UnknownDatasetStorageFormatType::serialize(
| ------------------------------------------ required by a bound introduced by this call
...
1483 | serializer,
| ^^^^^^^^^^ the trait `Serializer` is not implemented for `&std::option::Option`
|
= help: the following other types implement trait `Serializer`:
&'a mut serde_json::ser::Serializer
&mut Formatter<'a>
quick_xml::se::Serializer<'w, 'r, W>
quick_xml::se::content::ContentSerializer<'w, 'i, W>
quick_xml::se::element::ElementSerializer<'w, 'k, W>
quick_xml::se::key::QNameSerializer
quick_xml::se::simple_type::AtomicSerializer
quick_xml::se::simple_type::SimpleTypeSerializer
and 2 others
note: required by a bound in `generated::models::models::_::_serde::Serialize::serialize`
--> C:\Users\antk\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde_core-1.0.228\src\ser\mod.rs:267:12
|
265 | fn serialize(&self, serializer: S) -> Result
| --------- required by a bound in this associated function
266 | where
267 | S: Serializer;
| ^^^^^^^^^^ required by this bound in `Serialize::serialize`

error[E0277]: the trait bound `&std::option::Option: serde::Serializer` is not satisfied
--> spec\rmDataFactory\src\generated\models\unions_serde.rs:1476:18
|
1476 | } => UnknownDatasetStorageFormatType::serialize(
| __________________^
1477 | | &UnknownDatasetStorageFormatType {
1478 | | additional_properties,
1479 | | deserializer,
... |
1483 | | serializer,
1484 | | ),
| |_____________^ the trait `Serializer` is not implemented for `&std::option::Option`
|
= help: the following other types implement trait `Serializer`:
&'a mut serde_json::ser::Serializer
&mut Formatter<'a>
quick_xml::se::Serializer<'w, 'r, W>
quick_xml::se::content::ContentSerializer<'w, 'i, W>
quick_xml::se::element::ElementSerializer<'w, 'k, W>
quick_xml::se::key::QNameSerializer
quick_xml::se::simple_type::AtomicSerializer
quick_xml::se::simple_type::SimpleTypeSerializer
and 2 others
```

Generated code
```rs
// unions_serde.rs

impl Serialize for DatasetStorageFormat {
fn serialize(&self, serializer: S) -> Result
where
S: Serializer,
{
match self {
DatasetStorageFormat::AvroFormat(avro_format) => {
AvroFormat::serialize(avro_format, serializer)
}
DatasetStorageFormat::JsonFormatNew(json_format_new) => {
JsonFormatNew::serialize(json_format_new, serializer)
}
DatasetStorageFormat::OrcFormat(orc_format) => {
OrcFormat::serialize(orc_format, serializer)
}
DatasetStorageFormat::ParquetFormat(parquet_format) => {
ParquetFormat::serialize(parquet_format, serializer)
}
DatasetStorageFormat::TextFormat(text_format) => {
TextFormat::serialize(text_format, serializer)
}
DatasetStorageFormat::UnknownType {
additional_properties,
deserializer,
serializer,
type_prop,
} => UnknownDatasetStorageFormatType::serialize(
&UnknownDatasetStorageFormatType {
additional_properties,
deserializer,
serializer,
type_prop,
},
serializer,
),
}
}
}
```

and

```rs
// unions.rs

#[doc = r#"The format definition of a storage."#]
#[derive(Clone, Deserialize, SafeDebug)]
#[serde(tag = "type")]
pub enum DatasetStorageFormat {
AvroFormat(AvroFormat),

#[serde(rename = "JsonFormat")]
JsonFormatNew(JsonFormatNew),

OrcFormat(OrcFormat),

ParquetFormat(ParquetFormat),

TextFormat(TextFormat),

#[serde(untagged)]
UnknownType {
/// Contains unnamed additional properties.
additional_properties: Option>,

/// Deserializer. Type: string (or Expression with resultType string).
deserializer: Option,

/// Serializer. Type: string (or Expression with resultType string).
serializer: Option,

/// Type of dataset storage format.
type_prop: Option,
},
}
```

tsp:
```tsp
/**
* The format definition of a storage.
*/
@discriminator("type")
model DatasetStorageFormat {
...Record;

/**
* Type of dataset storage format.
*/
#suppress "@azure-tools/typespec-azure-core/no-string-discriminator" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
type: string;

/**
* Serializer. Type: string (or Expression with resultType string).
*/
serializer?: Dfe;

/**
* Deserializer. Type: string (or Expression with resultType string).
*/
deserializer?: Dfe;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.