Skip to content

Commit d383a09

Browse files
authored
linera-views-derive: minor cleanups (#3854)
## Motivation I wanted to [add a `view(skip)` directive to `linera-views-derive`](#3845) in order to facilitate the [removal of the `Extra` type from `linera_views::Context`](#1948), but it turns out to be more effort than it's worth to get skipped fields into the struct when loading. However, while I was there I made a couple of tweaks to `linera-views-derive` that I think are improvements. ## Proposal - add new constraints to `*View` implementations where they're required, rather than relying on the consumer to add them: recursive constraints on the field types, and `Self: Send + Sync` since we rely on `async_trait` - this should make the library more robust in the face of different uses, and also provide slightly better errors when misused - use `deluxe` for attribute parsing instead of doing it by hand: this is less of a win than it was originally since without `view(skip)` we only have one attribute to parse, but at least makes it easier to add more in the future - parse types for the `context` attribute rather than strings - use the [`quote` repetition syntax](https://docs.rs/quote/latest/quote/macro.quote.html#interpolation) to save some code <!-- Summarize the proposed changes and how they address the goal(s) stated above. --> ## Test Plan CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 8b18872 commit d383a09

File tree

74 files changed

+710
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+710
-208
lines changed

Cargo.lock

Lines changed: 56 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ criterion = { version = "0.5.1", default-features = false }
7777
crossbeam-channel = "0.5.14"
7878
custom_debug_derive = "0.6.1"
7979
dashmap = "5.5.3"
80+
deluxe = "0.5.0"
8081
derive_more = "1.0.0"
8182
dirs = "5.0.1"
8283
dyn-clone = "1.0.17"

examples/Cargo.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/amm/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use linera_sdk::{
88
};
99

1010
#[derive(RootView, async_graphql::SimpleObject)]
11-
#[view(context = "ViewStorageContext")]
11+
#[view(context = ViewStorageContext)]
1212
pub struct AmmState {
1313
pub shares: MapView<Account, Amount>,
1414
pub total_shares_supply: RegisterView<Amount>,

examples/counter-no-graphql/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use linera_sdk::views::{linera_views, RegisterView, RootView, ViewStorageContext
55

66
/// The application state.
77
#[derive(RootView)]
8-
#[view(context = "ViewStorageContext")]
8+
#[view(context = ViewStorageContext)]
99
pub struct CounterState {
1010
pub value: RegisterView<u64>,
1111
}

examples/counter/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use linera_sdk::views::{linera_views, RegisterView, RootView, ViewStorageContext
55

66
/// The application state.
77
#[derive(RootView)]
8-
#[view(context = "ViewStorageContext")]
8+
#[view(context = ViewStorageContext)]
99
pub struct CounterState {
1010
pub value: RegisterView<u64>,
1111
}

examples/crowd-funding/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ scalar!(Status);
2525

2626
/// The crowd-funding campaign's state.
2727
#[derive(RootView, async_graphql::SimpleObject)]
28-
#[view(context = "ViewStorageContext")]
28+
#[view(context = ViewStorageContext)]
2929
pub struct CrowdFundingState {
3030
/// The status of the campaign.
3131
pub status: RegisterView<Status>,

examples/ethereum-tracker/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use linera_sdk::views::{linera_views, MapView, RegisterView, RootView, ViewStora
66

77
/// The application state.
88
#[derive(RootView, async_graphql::SimpleObject)]
9-
#[view(context = "ViewStorageContext")]
9+
#[view(context = ViewStorageContext)]
1010
pub struct EthereumTrackerState {
1111
pub ethereum_endpoint: RegisterView<String>,
1212
pub contract_address: RegisterView<String>,

examples/fungible/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use linera_sdk::{
99

1010
/// The application state.
1111
#[derive(RootView)]
12-
#[view(context = "ViewStorageContext")]
12+
#[view(context = ViewStorageContext)]
1313
pub struct FungibleTokenState {
1414
pub accounts: MapView<AccountOwner, Amount>,
1515
}

examples/gen-nft/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use linera_sdk::{
1212

1313
/// The application state.
1414
#[derive(RootView, SimpleObject)]
15-
#[view(context = "ViewStorageContext")]
15+
#[view(context = ViewStorageContext)]
1616
pub struct GenNftState {
1717
// Map from token ID to the NFT data
1818
pub nfts: MapView<TokenId, Nft>,

0 commit comments

Comments
 (0)