Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
When a field is labeled with #[serde(default)] it means that if that field is not present, it is populated using the Default impl for the field's type:
#[derive(Serialize, Deserialize, Clone, Debug)]
struct Foo {
#[serde(default)]
bar: Bar,
}
Foo { bar: Bar::default() }
This is not the behaviour we want, however. We want fields that have not been supplied to be populated with their value from the Default impl of the type they are part of:
Foo { bar: Foo::default().bar }
Implementing this manually requires a lot of boilerplate -- each field needs to have an associated function that returns its default value:
#[derive(Serialize, Deserialize, Clone, Debug)]
struct Foo {
#[serde(default = "Foo::__default_bar")]
bar: Bar,
}
So this PR introduces an attribute proc macro to perform this transformation:
#[GraphQLConfig]
struct Foo {
bar: Bar,
}
It also performs some other related clean-ups:
Moves default values inline into the respective Default impls, to prevent them being used in isolation.
Move the documentation for what the field is onto the struct definition, and the documentation for how the default was chosen onto the Default impl.
Moved the implementation of Display for Version.
Got rid of ConnectionConfig::ci_integration_test_cfg as it is the same as its Default impl now.
Improved various docs about what various configs are.
Test plan
Added a test for reading a ServiceConfig from an incomplete/partial TOML:
sui-graphql-rpc$ cargo nextest run -- read_partial_in_service_config
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.
[ ] Protocol:
[ ] Nodes (Validators and Full nodes):
[ ] Indexer:
[ ] JSON-RPC:
[x] GraphQL: Fix a bug where starting the service using a config with not all fields set would result in the unset fields being zeroed out rather than taking their usual default values (as would happen if no config had been explicitly supplied).
Description
When a field is labeled with
#[serde(default)]
it means that if that field is not present, it is populated using theDefault
impl for the field's type:This is not the behaviour we want, however. We want fields that have not been supplied to be populated with their value from the
Default
impl of the type they are part of:Implementing this manually requires a lot of boilerplate -- each field needs to have an associated function that returns its default value:
So this PR introduces an attribute proc macro to perform this transformation:
It also performs some other related clean-ups:
Default
impls, to prevent them being used in isolation.Default
impl.Display
forVersion
.ConnectionConfig::ci_integration_test_cfg
as it is the same as itsDefault
impl now.Test plan
Added a test for reading a
ServiceConfig
from an incomplete/partial TOML:Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.