diff --git a/examples/amm/src/contract.rs b/examples/amm/src/contract.rs index 841536559477..bfd8997ed5fb 100644 --- a/examples/amm/src/contract.rs +++ b/examples/amm/src/contract.rs @@ -9,7 +9,7 @@ use amm::{AmmAbi, Message, Operation, Parameters}; use fungible::{Account, FungibleTokenAbi}; use linera_sdk::{ base::{AccountOwner, Amount, ApplicationId, ChainId, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; use num_bigint::BigUint; @@ -34,7 +34,7 @@ impl Contract for AmmContract { type Parameters = Parameters; async fn load(runtime: ContractRuntime) -> Self { - let state = Amm::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Amm::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); AmmContract { state, runtime } diff --git a/examples/amm/src/service.rs b/examples/amm/src/service.rs index 8ab2c2c2f4f1..19066a3bba07 100644 --- a/examples/amm/src/service.rs +++ b/examples/amm/src/service.rs @@ -10,10 +10,7 @@ use std::sync::Arc; use amm::{Operation, Parameters}; use async_graphql::{EmptySubscription, Request, Response, Schema}; use linera_sdk::{ - base::WithServiceAbi, - graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, + base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime, }; use self::state::Amm; @@ -32,7 +29,7 @@ impl Service for AmmService { type Parameters = Parameters; async fn new(runtime: ServiceRuntime) -> Self { - let state = Amm::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Amm::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); AmmService { diff --git a/examples/counter/src/contract.rs b/examples/counter/src/contract.rs index c88449f09044..af437a048f5e 100644 --- a/examples/counter/src/contract.rs +++ b/examples/counter/src/contract.rs @@ -8,7 +8,7 @@ mod state; use counter::CounterAbi; use linera_sdk::{ base::WithContractAbi, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; @@ -31,7 +31,7 @@ impl Contract for CounterContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = Counter::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Counter::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); CounterContract { state, runtime } @@ -62,11 +62,7 @@ impl Contract for CounterContract { #[cfg(test)] mod tests { use futures::FutureExt as _; - use linera_sdk::{ - util::BlockingWait, - views::{View, ViewStorageContext}, - Contract, ContractRuntime, - }; + use linera_sdk::{util::BlockingWait, views::View, Contract, ContractRuntime}; use super::{Counter, CounterContract}; @@ -121,7 +117,7 @@ mod tests { fn create_and_instantiate_counter(initial_value: u64) -> CounterContract { let runtime = ContractRuntime::new().with_application_parameters(()); let mut contract = CounterContract { - state: Counter::load(ViewStorageContext::from(runtime.key_value_store())) + state: Counter::load(runtime.root_view_storage_context()) .blocking_wait() .expect("Failed to read from mock key value store"), runtime, diff --git a/examples/counter/src/service.rs b/examples/counter/src/service.rs index 6347734852e5..1846f6bd8703 100644 --- a/examples/counter/src/service.rs +++ b/examples/counter/src/service.rs @@ -6,11 +6,7 @@ mod state; use async_graphql::{EmptySubscription, Object, Request, Response, Schema}; -use linera_sdk::{ - base::WithServiceAbi, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, -}; +use linera_sdk::{base::WithServiceAbi, views::View, Service, ServiceRuntime}; use self::state::Counter; @@ -28,7 +24,7 @@ impl Service for CounterService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = Counter::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Counter::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); CounterService { state } @@ -71,11 +67,7 @@ impl QueryRoot { mod tests { use async_graphql::{Request, Response, Value}; use futures::FutureExt as _; - use linera_sdk::{ - util::BlockingWait, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, - }; + use linera_sdk::{util::BlockingWait, views::View, Service, ServiceRuntime}; use serde_json::json; use super::{Counter, CounterService}; @@ -84,7 +76,7 @@ mod tests { fn query() { let value = 61_098_721_u64; let runtime = ServiceRuntime::::new(); - let mut state = Counter::load(ViewStorageContext::from(runtime.key_value_store())) + let mut state = Counter::load(runtime.root_view_storage_context()) .blocking_wait() .expect("Failed to read from mock key value store"); state.value.set(value); diff --git a/examples/crowd-funding/src/contract.rs b/examples/crowd-funding/src/contract.rs index fe366d0ff898..9c2d8f72a09c 100644 --- a/examples/crowd-funding/src/contract.rs +++ b/examples/crowd-funding/src/contract.rs @@ -9,7 +9,7 @@ use crowd_funding::{CrowdFundingAbi, InstantiationArgument, Message, Operation}; use fungible::{Account, FungibleTokenAbi}; use linera_sdk::{ base::{AccountOwner, Amount, ApplicationId, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; use state::{CrowdFunding, Status}; @@ -31,7 +31,7 @@ impl Contract for CrowdFundingContract { type Parameters = ApplicationId; async fn load(runtime: ContractRuntime) -> Self { - let state = CrowdFunding::load(ViewStorageContext::from(runtime.key_value_store())) + let state = CrowdFunding::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); CrowdFundingContract { state, runtime } diff --git a/examples/crowd-funding/src/service.rs b/examples/crowd-funding/src/service.rs index 409ce37ea96b..a24f54ecd8c5 100644 --- a/examples/crowd-funding/src/service.rs +++ b/examples/crowd-funding/src/service.rs @@ -12,7 +12,7 @@ use crowd_funding::Operation; use linera_sdk::{ base::{ApplicationId, WithServiceAbi}, graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, + views::View, Service, ServiceRuntime, }; use state::CrowdFunding; @@ -31,7 +31,7 @@ impl Service for CrowdFundingService { type Parameters = ApplicationId; async fn new(runtime: ServiceRuntime) -> Self { - let state = CrowdFunding::load(ViewStorageContext::from(runtime.key_value_store())) + let state = CrowdFunding::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); CrowdFundingService { diff --git a/examples/ethereum-tracker/src/contract.rs b/examples/ethereum-tracker/src/contract.rs index a7a2a94bf8c2..e3fc1b1bfc7a 100644 --- a/examples/ethereum-tracker/src/contract.rs +++ b/examples/ethereum-tracker/src/contract.rs @@ -9,7 +9,7 @@ use ethereum_tracker::{EthereumTrackerAbi, InstantiationArgument, U256Cont}; use linera_sdk::{ base::WithContractAbi, ethereum::{EthereumClient, EthereumDataType, EthereumQueries as _}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; @@ -32,7 +32,7 @@ impl Contract for EthereumTrackerContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = EthereumTracker::load(ViewStorageContext::from(runtime.key_value_store())) + let state = EthereumTracker::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); EthereumTrackerContract { state, runtime } diff --git a/examples/ethereum-tracker/src/service.rs b/examples/ethereum-tracker/src/service.rs index 6e56b02fb3c9..1b8e6d2ada1a 100644 --- a/examples/ethereum-tracker/src/service.rs +++ b/examples/ethereum-tracker/src/service.rs @@ -10,10 +10,7 @@ use std::sync::Arc; use async_graphql::{EmptySubscription, Request, Response, Schema}; use ethereum_tracker::Operation; use linera_sdk::{ - base::WithServiceAbi, - graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, + base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime, }; use self::state::EthereumTracker; @@ -33,7 +30,7 @@ impl Service for EthereumTrackerService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = EthereumTracker::load(ViewStorageContext::from(runtime.key_value_store())) + let state = EthereumTracker::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); EthereumTrackerService { diff --git a/examples/fungible/src/contract.rs b/examples/fungible/src/contract.rs index daa0ea639f2e..d36fefb4daa7 100644 --- a/examples/fungible/src/contract.rs +++ b/examples/fungible/src/contract.rs @@ -12,7 +12,7 @@ use fungible::{ }; use linera_sdk::{ base::{AccountOwner, Amount, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; @@ -35,7 +35,7 @@ impl Contract for FungibleTokenContract { type InstantiationArgument = InitialState; async fn load(runtime: ContractRuntime) -> Self { - let state = FungibleToken::load(ViewStorageContext::from(runtime.key_value_store())) + let state = FungibleToken::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); FungibleTokenContract { state, runtime } diff --git a/examples/fungible/src/service.rs b/examples/fungible/src/service.rs index 39e3023fa19d..7d4c17ca88ec 100644 --- a/examples/fungible/src/service.rs +++ b/examples/fungible/src/service.rs @@ -12,7 +12,7 @@ use fungible::{Operation, Parameters}; use linera_sdk::{ base::{AccountOwner, Amount, WithServiceAbi}, graphql::GraphQLMutationRoot, - views::{MapView, View, ViewStorageContext}, + views::{MapView, View}, Service, ServiceRuntime, }; @@ -34,7 +34,7 @@ impl Service for FungibleTokenService { type Parameters = Parameters; async fn new(runtime: ServiceRuntime) -> Self { - let state = FungibleToken::load(ViewStorageContext::from(runtime.key_value_store())) + let state = FungibleToken::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); FungibleTokenService { diff --git a/examples/gen-nft/src/contract.rs b/examples/gen-nft/src/contract.rs index 4e9ae8765686..5744d8078811 100644 --- a/examples/gen-nft/src/contract.rs +++ b/examples/gen-nft/src/contract.rs @@ -11,7 +11,7 @@ use fungible::Account; use gen_nft::{GenNftAbi, Message, Nft, Operation, TokenId}; use linera_sdk::{ base::{AccountOwner, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; @@ -34,7 +34,7 @@ impl Contract for GenNftContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = GenNft::load(ViewStorageContext::from(runtime.key_value_store())) + let state = GenNft::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); GenNftContract { state, runtime } diff --git a/examples/gen-nft/src/service.rs b/examples/gen-nft/src/service.rs index 95dce8a66103..5584b46a2182 100644 --- a/examples/gen-nft/src/service.rs +++ b/examples/gen-nft/src/service.rs @@ -19,7 +19,7 @@ use fungible::Account; use gen_nft::{NftOutput, Operation, TokenId}; use linera_sdk::{ base::{AccountOwner, WithServiceAbi}, - views::{View, ViewStorageContext}, + views::View, Service, ServiceRuntime, }; use log::info; @@ -42,7 +42,7 @@ impl Service for GenNftService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = GenNft::load(ViewStorageContext::from(runtime.key_value_store())) + let state = GenNft::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); GenNftService { diff --git a/examples/hex-game/src/contract.rs b/examples/hex-game/src/contract.rs index 017f7c3b2be4..343c94aa22a3 100644 --- a/examples/hex-game/src/contract.rs +++ b/examples/hex-game/src/contract.rs @@ -12,7 +12,7 @@ use linera_sdk::{ Amount, ApplicationPermissions, ChainId, ChainOwnership, Owner, PublicKey, TimeoutConfig, WithContractAbi, }, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; use serde::{Deserialize, Serialize}; @@ -35,7 +35,7 @@ impl Contract for HexContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = HexState::load(ViewStorageContext::from(runtime.key_value_store())) + let state = HexState::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); HexContract { state, runtime } diff --git a/examples/hex-game/src/service.rs b/examples/hex-game/src/service.rs index 67a6af2535f9..7c63cde44639 100644 --- a/examples/hex-game/src/service.rs +++ b/examples/hex-game/src/service.rs @@ -10,10 +10,7 @@ use std::sync::{Arc, Mutex}; use async_graphql::{ComplexObject, Context, EmptySubscription, Request, Response, Schema}; use hex_game::{Operation, Player}; use linera_sdk::{ - base::WithServiceAbi, - graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, + base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime, }; use self::state::HexState; @@ -34,7 +31,7 @@ impl Service for HexService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = HexState::load(ViewStorageContext::from(runtime.key_value_store())) + let state = HexState::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); HexService { @@ -76,11 +73,7 @@ impl HexState { #[cfg(test)] mod tests { use async_graphql::{futures_util::FutureExt, Request}; - use linera_sdk::{ - util::BlockingWait, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, - }; + use linera_sdk::{util::BlockingWait, views::View, Service, ServiceRuntime}; use serde_json::json; use super::*; @@ -88,7 +81,7 @@ mod tests { #[test] fn query() { let runtime = ServiceRuntime::::new(); - let state = HexState::load(ViewStorageContext::from(runtime.key_value_store())) + let state = HexState::load(runtime.root_view_storage_context()) .blocking_wait() .expect("Failed to read from mock key value store"); diff --git a/examples/matching-engine/src/contract.rs b/examples/matching-engine/src/contract.rs index 87c6ca2a1caf..740946025a6a 100644 --- a/examples/matching-engine/src/contract.rs +++ b/examples/matching-engine/src/contract.rs @@ -9,7 +9,7 @@ use std::cmp::min; use fungible::{Account, FungibleTokenAbi}; use linera_sdk::{ base::{AccountOwner, Amount, ApplicationId, ChainId, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; use matching_engine::{ @@ -57,7 +57,7 @@ impl Contract for MatchingEngineContract { type Parameters = Parameters; async fn load(runtime: ContractRuntime) -> Self { - let state = MatchingEngine::load(ViewStorageContext::from(runtime.key_value_store())) + let state = MatchingEngine::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); MatchingEngineContract { state, runtime } diff --git a/examples/matching-engine/src/service.rs b/examples/matching-engine/src/service.rs index 02e792bfac95..46f93ea7bca6 100644 --- a/examples/matching-engine/src/service.rs +++ b/examples/matching-engine/src/service.rs @@ -9,10 +9,7 @@ use std::sync::Arc; use async_graphql::{EmptySubscription, Request, Response, Schema}; use linera_sdk::{ - base::WithServiceAbi, - graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, + base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime, }; use matching_engine::{Operation, Parameters}; @@ -32,7 +29,7 @@ impl Service for MatchingEngineService { type Parameters = Parameters; async fn new(runtime: ServiceRuntime) -> Self { - let state = MatchingEngine::load(ViewStorageContext::from(runtime.key_value_store())) + let state = MatchingEngine::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); MatchingEngineService { diff --git a/examples/non-fungible/src/contract.rs b/examples/non-fungible/src/contract.rs index 6fc126f57597..b732bd093ae2 100644 --- a/examples/non-fungible/src/contract.rs +++ b/examples/non-fungible/src/contract.rs @@ -10,7 +10,7 @@ use std::collections::BTreeSet; use fungible::Account; use linera_sdk::{ base::{AccountOwner, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, DataBlobHash, }; use non_fungible::{Message, Nft, NonFungibleTokenAbi, Operation, TokenId}; @@ -34,7 +34,7 @@ impl Contract for NonFungibleTokenContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = NonFungibleToken::load(ViewStorageContext::from(runtime.key_value_store())) + let state = NonFungibleToken::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); NonFungibleTokenContract { state, runtime } diff --git a/examples/non-fungible/src/service.rs b/examples/non-fungible/src/service.rs index 1038800cc550..f7c6b84cbe70 100644 --- a/examples/non-fungible/src/service.rs +++ b/examples/non-fungible/src/service.rs @@ -15,7 +15,7 @@ use base64::engine::{general_purpose::STANDARD_NO_PAD, Engine as _}; use fungible::Account; use linera_sdk::{ base::{AccountOwner, WithServiceAbi}, - views::{View, ViewStorageContext}, + views::View, DataBlobHash, Service, ServiceRuntime, }; use non_fungible::{NftOutput, Operation, TokenId}; @@ -37,7 +37,7 @@ impl Service for NonFungibleTokenService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = NonFungibleToken::load(ViewStorageContext::from(runtime.key_value_store())) + let state = NonFungibleToken::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); NonFungibleTokenService { diff --git a/examples/social/src/contract.rs b/examples/social/src/contract.rs index 85e1a7678518..2d4c32c487d9 100644 --- a/examples/social/src/contract.rs +++ b/examples/social/src/contract.rs @@ -7,7 +7,7 @@ mod state; use linera_sdk::{ base::{ChainId, ChannelName, Destination, MessageId, WithContractAbi}, - views::{RootView, View, ViewStorageContext}, + views::{RootView, View}, Contract, ContractRuntime, }; use social::{Comment, Key, Message, Operation, OwnPost, Post, SocialAbi}; @@ -33,7 +33,7 @@ impl Contract for SocialContract { type Parameters = (); async fn load(runtime: ContractRuntime) -> Self { - let state = Social::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Social::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); SocialContract { state, runtime } diff --git a/examples/social/src/service.rs b/examples/social/src/service.rs index c56f098f71a3..9c47cf780592 100644 --- a/examples/social/src/service.rs +++ b/examples/social/src/service.rs @@ -9,10 +9,7 @@ use std::sync::Arc; use async_graphql::{EmptySubscription, Request, Response, Schema}; use linera_sdk::{ - base::WithServiceAbi, - graphql::GraphQLMutationRoot, - views::{View, ViewStorageContext}, - Service, ServiceRuntime, + base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime, }; use social::Operation; use state::Social; @@ -31,7 +28,7 @@ impl Service for SocialService { type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self { - let state = Social::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Social::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); SocialService { diff --git a/linera-chain/src/inbox.rs b/linera-chain/src/inbox.rs index a2d6325f18fe..ad73b8bc5d75 100644 --- a/linera-chain/src/inbox.rs +++ b/linera-chain/src/inbox.rs @@ -8,7 +8,7 @@ use linera_base::{ identifiers::ChainId, }; #[cfg(with_testing)] -use linera_views::memory::{create_test_memory_context, MemoryContext}; +use linera_views::context::{create_test_memory_context, MemoryContext}; use linera_views::{ context::Context, queue_view::QueueView, diff --git a/linera-chain/src/outbox.rs b/linera-chain/src/outbox.rs index 64c72fa48ecb..9043796301df 100644 --- a/linera-chain/src/outbox.rs +++ b/linera-chain/src/outbox.rs @@ -3,7 +3,7 @@ use linera_base::data_types::{ArithmeticError, BlockHeight}; #[cfg(with_testing)] -use linera_views::memory::{create_test_memory_context, MemoryContext}; +use linera_views::context::{create_test_memory_context, MemoryContext}; use linera_views::{ context::Context, queue_view::QueueView, diff --git a/linera-chain/src/unit_tests/chain_tests.rs b/linera-chain/src/unit_tests/chain_tests.rs index 69b8d5fb98b5..2dd1c1812fec 100644 --- a/linera-chain/src/unit_tests/chain_tests.rs +++ b/linera-chain/src/unit_tests/chain_tests.rs @@ -22,8 +22,8 @@ use linera_execution::{ SystemMessage, TestExecutionRuntimeContext, }; use linera_views::{ - context::Context as _, - memory::{MemoryContext, TEST_MEMORY_MAX_STREAM_QUERIES}, + context::{Context as _, MemoryContext}, + memory::TEST_MEMORY_MAX_STREAM_QUERIES, test_utils::generate_test_namespace, views::{View, ViewError}, }; diff --git a/linera-core/src/unit_tests/worker_tests.rs b/linera-core/src/unit_tests/worker_tests.rs index 421bbb252fc0..76f5d902d6cf 100644 --- a/linera-core/src/unit_tests/worker_tests.rs +++ b/linera-core/src/unit_tests/worker_tests.rs @@ -43,7 +43,8 @@ use linera_execution::{ }; use linera_storage::{DbStorage, Storage, TestClock}; use linera_views::{ - memory::{create_memory_store_test_config, MemoryContext, MemoryStore}, + context::MemoryContext, + memory::{create_memory_store_test_config, MemoryStore}, test_utils::generate_test_namespace, views::{CryptoHashView, RootView}, }; diff --git a/linera-execution/src/applications.rs b/linera-execution/src/applications.rs index 87f9ea657a7d..2d12a0f2a3c7 100644 --- a/linera-execution/src/applications.rs +++ b/linera-execution/src/applications.rs @@ -11,7 +11,7 @@ use linera_views::{ }; #[cfg(with_testing)] use { - linera_views::memory::{create_test_memory_context, MemoryContext}, + linera_views::context::{create_test_memory_context, MemoryContext}, linera_views::views::View, std::collections::BTreeMap, }; diff --git a/linera-execution/src/execution.rs b/linera-execution/src/execution.rs index 1ec66745255a..47de181c7c4e 100644 --- a/linera-execution/src/execution.rs +++ b/linera-execution/src/execution.rs @@ -23,7 +23,7 @@ use { crate::{ ResourceControlPolicy, ResourceTracker, TestExecutionRuntimeContext, UserContractCode, }, - linera_views::memory::MemoryContext, + linera_views::context::MemoryContext, std::sync::Arc, }; diff --git a/linera-execution/src/system.rs b/linera-execution/src/system.rs index e4770fd8a350..a1ca2be38635 100644 --- a/linera-execution/src/system.rs +++ b/linera-execution/src/system.rs @@ -996,7 +996,7 @@ where #[cfg(test)] mod tests { use linera_base::{crypto::CryptoHash, data_types::BlockHeight, identifiers::ApplicationId}; - use linera_views::memory::MemoryContext; + use linera_views::context::MemoryContext; use super::*; use crate::{ExecutionOutcome, ExecutionStateView, TestExecutionRuntimeContext}; diff --git a/linera-execution/src/test_utils/system_execution_state.rs b/linera-execution/src/test_utils/system_execution_state.rs index 9ce31ebaa484..d5709091a56a 100644 --- a/linera-execution/src/test_utils/system_execution_state.rs +++ b/linera-execution/src/test_utils/system_execution_state.rs @@ -13,8 +13,8 @@ use linera_base::{ ownership::ChainOwnership, }; use linera_views::{ - context::Context, - memory::{MemoryContext, TEST_MEMORY_MAX_STREAM_QUERIES}, + context::{Context, MemoryContext}, + memory::TEST_MEMORY_MAX_STREAM_QUERIES, test_utils::generate_test_namespace, views::{CryptoHashView, View, ViewError}, }; diff --git a/linera-indexer/lib/src/indexer.rs b/linera-indexer/lib/src/indexer.rs index 3cccbef7ed92..e3a580d7a8a9 100644 --- a/linera-indexer/lib/src/indexer.rs +++ b/linera-indexer/lib/src/indexer.rs @@ -12,7 +12,7 @@ use linera_base::{crypto::CryptoHash, data_types::BlockHeight, identifiers::Chai use linera_chain::data_types::HashedCertificateValue; use linera_views::{ common::KeyValueStore, - context::{Context, ContextFromStore}, + context::{Context, ViewContext}, map_view::MapView, register_view::RegisterView, set_view::SetView, @@ -39,10 +39,10 @@ pub struct StateView { #[derive(Clone)] pub struct State(Arc>>); -type StateSchema = Schema>, EmptyMutation, EmptySubscription>; +type StateSchema = Schema>, EmptyMutation, EmptySubscription>; pub struct Indexer { - pub state: State>, + pub state: State>, pub plugins: BTreeMap>>, } @@ -73,7 +73,7 @@ where let store = store .clone_with_root_key(&root_key) .map_err(|_e| IndexerError::CloneWithRootKeyError)?; - let context = ContextFromStore::create(store, ()) + let context = ViewContext::create_root_context(store, ()) .await .map_err(|e| IndexerError::ViewError(e.into()))?; let state = State(Arc::new(Mutex::new(StateView::load(context).await?))); @@ -87,7 +87,7 @@ where /// the indexer. pub async fn process_value( &self, - state: &mut StateView>, + state: &mut StateView>, value: &HashedCertificateValue, ) -> Result<(), IndexerError> { for plugin in self.plugins.values() { diff --git a/linera-indexer/lib/src/plugin.rs b/linera-indexer/lib/src/plugin.rs index cd282bdc21d7..67040fc648b8 100644 --- a/linera-indexer/lib/src/plugin.rs +++ b/linera-indexer/lib/src/plugin.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use async_graphql::{EmptyMutation, EmptySubscription, ObjectType, Schema}; use axum::Router; use linera_chain::data_types::HashedCertificateValue; -use linera_views::{common::KeyValueStore, context::ContextFromStore, views::View}; +use linera_views::{common::KeyValueStore, context::ViewContext, views::View}; use tokio::sync::Mutex; use crate::common::IndexerError; @@ -63,7 +63,7 @@ pub fn route(name: &str, query: Q, app: axum::Router) - .layer(tower_http::cors::CorsLayer::permissive()) } -pub async fn load>>( +pub async fn load>>( store: S, name: &str, ) -> Result>, IndexerError> @@ -75,7 +75,7 @@ where let store = store .clone_with_root_key(&root_key) .map_err(|_e| IndexerError::CloneWithRootKeyError)?; - let context = ContextFromStore::create(store, ()) + let context = ViewContext::create_root_context(store, ()) .await .map_err(|e| IndexerError::ViewError(e.into()))?; let plugin = V::load(context).await?; diff --git a/linera-indexer/plugins/src/operations.rs b/linera-indexer/plugins/src/operations.rs index 0da567722086..9888eeb50821 100644 --- a/linera-indexer/plugins/src/operations.rs +++ b/linera-indexer/plugins/src/operations.rs @@ -17,7 +17,7 @@ use linera_indexer::{ }; use linera_views::{ common::KeyValueStore, - context::{Context, ContextFromStore}, + context::{Context, ViewContext}, map_view::MapView, views::RootView, }; @@ -110,7 +110,7 @@ static NAME: &str = "operations"; /// Implements `Plugin` #[async_trait::async_trait] -impl Plugin for OperationsPlugin> +impl Plugin for OperationsPlugin> where S: KeyValueStore + Clone + Send + Sync + 'static, S::Error: From + Send + Sync + std::error::Error + 'static, diff --git a/linera-sdk/src/contract/runtime.rs b/linera-sdk/src/contract/runtime.rs index 8a8f57035c10..312c9f572158 100644 --- a/linera-sdk/src/contract/runtime.rs +++ b/linera-sdk/src/contract/runtime.rs @@ -16,7 +16,7 @@ use linera_base::{ use serde::Serialize; use super::wit::contract_system_api as wit; -use crate::{Contract, DataBlobHash, KeyValueStore}; +use crate::{Contract, DataBlobHash, KeyValueStore, ViewStorageContext}; /// The common runtime to interface with the host executing the contract. /// @@ -63,6 +63,11 @@ where KeyValueStore::for_contracts() } + /// Returns a storage context suitable for a root view. + pub fn root_view_storage_context(&self) -> ViewStorageContext { + ViewStorageContext::new_unsafe(self.key_value_store(), Vec::new(), ()) + } + /// Returns the application parameters provided when the application was created. pub fn application_parameters(&mut self) -> Application::Parameters { self.application_parameters diff --git a/linera-sdk/src/contract/test_runtime.rs b/linera-sdk/src/contract/test_runtime.rs index 358344ce1fa6..5aecb22fd78e 100644 --- a/linera-sdk/src/contract/test_runtime.rs +++ b/linera-sdk/src/contract/test_runtime.rs @@ -20,7 +20,7 @@ use linera_base::{ }; use serde::Serialize; -use crate::{Contract, DataBlobHash, KeyValueStore}; +use crate::{Contract, DataBlobHash, KeyValueStore, ViewStorageContext}; /// A mock of the common runtime to interface with the host executing the contract. pub struct MockContractRuntime @@ -108,6 +108,11 @@ where self.key_value_store.clone() } + /// Returns a storage context suitable for a root view. + pub fn root_view_storage_context(&self) -> ViewStorageContext { + ViewStorageContext::new_unsafe(self.key_value_store(), Vec::new(), ()) + } + /// Configures the application parameters to return during the test. pub fn with_application_parameters( mut self, diff --git a/linera-sdk/src/lib.rs b/linera-sdk/src/lib.rs index 48a9aee82c53..255a58fb4893 100644 --- a/linera-sdk/src/lib.rs +++ b/linera-sdk/src/lib.rs @@ -65,7 +65,7 @@ pub use self::{ extensions::{FromBcsBytes, ToBcsBytes}, log::{ContractLogger, ServiceLogger}, service::ServiceRuntime, - views::KeyValueStore, + views::{KeyValueStore, ViewStorageContext}, }; /// Hash of a data blob. diff --git a/linera-sdk/src/service/runtime.rs b/linera-sdk/src/service/runtime.rs index 6229bdf697a6..e2aa3e4a1df9 100644 --- a/linera-sdk/src/service/runtime.rs +++ b/linera-sdk/src/service/runtime.rs @@ -12,7 +12,7 @@ use linera_base::{ }; use super::wit::service_system_api as wit; -use crate::{DataBlobHash, KeyValueStore, Service}; +use crate::{DataBlobHash, KeyValueStore, Service, ViewStorageContext}; /// The runtime available during execution of a query. pub struct ServiceRuntime @@ -52,6 +52,11 @@ where KeyValueStore::for_services() } + /// Returns a storage context suitable for a root view. + pub fn root_view_storage_context(&self) -> ViewStorageContext { + ViewStorageContext::new_unsafe(self.key_value_store(), Vec::new(), ()) + } + /// Returns the application parameters provided when the application was created. pub fn application_parameters(&self) -> Application::Parameters { Self::fetch_value_through_cache(&self.application_parameters, || { diff --git a/linera-sdk/src/service/test_runtime.rs b/linera-sdk/src/service/test_runtime.rs index ea4b8990d4b2..0c9939135a9f 100644 --- a/linera-sdk/src/service/test_runtime.rs +++ b/linera-sdk/src/service/test_runtime.rs @@ -14,7 +14,7 @@ use linera_base::{ identifiers::{ApplicationId, ChainId, Owner}, }; -use crate::{DataBlobHash, KeyValueStore, Service}; +use crate::{DataBlobHash, KeyValueStore, Service, ViewStorageContext}; /// The runtime available during execution of a query. pub struct MockServiceRuntime @@ -69,6 +69,11 @@ where self.key_value_store.clone() } + /// Returns a storage context suitable for a root view. + pub fn root_view_storage_context(&self) -> ViewStorageContext { + ViewStorageContext::new_unsafe(self.key_value_store(), Vec::new(), ()) + } + /// Configures the application parameters to return during the test. pub fn with_application_parameters( self, diff --git a/linera-sdk/src/test/mock_stubs.rs b/linera-sdk/src/test/mock_stubs.rs index 0f08422c0df1..459ea37e7692 100644 --- a/linera-sdk/src/test/mock_stubs.rs +++ b/linera-sdk/src/test/mock_stubs.rs @@ -12,7 +12,7 @@ use linera_base::{ data_types::{Amount, Timestamp}, identifiers::{ApplicationId, ChainId}, }; -use linera_views::memory::MemoryContext; +use linera_views::context::MemoryContext; use serde::Serialize; /// A helpful error message to explain why the mock API isn't available. diff --git a/linera-sdk/src/views/system_api.rs b/linera-sdk/src/views/system_api.rs index ec1cb5ad4ed9..fa7cc0897740 100644 --- a/linera-sdk/src/views/system_api.rs +++ b/linera-sdk/src/views/system_api.rs @@ -10,7 +10,6 @@ use linera_base::ensure; use linera_views::{ batch::Batch, common::{ReadableKeyValueStore, WithError, WritableKeyValueStore}, - context::ContextFromStore, }; use thiserror::Error; @@ -367,13 +366,7 @@ impl WitInterface { /// Implementation of [`linera_views::context::Context`] to be used for data storage /// by Linera applications. -pub type ViewStorageContext = ContextFromStore<(), KeyValueStore>; - -impl From for ViewStorageContext { - fn from(store: KeyValueStore) -> Self { - ContextFromStore::new_unsafe(store, Vec::new(), ()) - } -} +pub type ViewStorageContext = linera_views::context::ViewContext<(), KeyValueStore>; #[cfg(all(test, not(target_arch = "wasm32")))] mod tests { diff --git a/linera-service-graphql-client/gql/service_schema.graphql b/linera-service-graphql-client/gql/service_schema.graphql index 4d688b133d92..37a3b028981b 100644 --- a/linera-service-graphql-client/gql/service_schema.graphql +++ b/linera-service-graphql-client/gql/service_schema.graphql @@ -207,19 +207,19 @@ type ChainStateExtendedView { Hashes of all certified blocks for this sender. This ends with `block_hash` and has length `usize::from(next_block_height)`. """ - confirmedLog: LogView_CryptoHash_20eccc8d! + confirmedLog: LogView_CryptoHash_b39baa6c! """ Sender chain and height of all certified blocks known as a receiver (local ordering). """ - receivedLog: LogView_ChainAndHeight_c25ecaa6! + receivedLog: LogView_ChainAndHeight_74e1b2c7! """ Mailboxes used to receive messages indexed by their origin. """ - inboxes: ReentrantCollectionView_Origin_InboxStateView_3485213288! + inboxes: ReentrantCollectionView_Origin_InboxStateView_1712852561! """ A queue of unskippable bundles, with the timestamp when we added them to the inbox. """ - unskippableBundles: QueueView_TimestampedBundleInInbox_cdcf52b8! + unskippableBundles: QueueView_TimestampedBundleInInbox_f9f36704! """ Unskippable bundles that have been removed but are still in the queue. """ @@ -227,7 +227,7 @@ type ChainStateExtendedView { """ Mailboxes used to send messages, indexed by their target. """ - outboxes: ReentrantCollectionView_Target_OutboxStateView_4197956612! + outboxes: ReentrantCollectionView_Target_OutboxStateView_2644302559! """ Number of outgoing messages in flight for each block height. We use a `RegisterView` to prioritize speed for small maps. @@ -236,7 +236,7 @@ type ChainStateExtendedView { """ Channels able to multicast messages to subscribers. """ - channels: ReentrantCollectionView_ChannelFullName_ChannelStateView_4201533849! + channels: ReentrantCollectionView_ChannelFullName_ChannelStateView_394492371! } """ @@ -291,7 +291,7 @@ type ChannelStateView { """ The block heights so far, to be sent to future subscribers. """ - blockHeights: LogView_BlockHeight_db6bcc27! + blockHeights: LogView_BlockHeight_be3af4a4! } """ @@ -357,7 +357,7 @@ scalar Destination """ A GraphQL-visible map item, complete with key. """ -type Entry_ChannelFullName_ChannelStateView_84ad3897 { +type Entry_ChannelFullName_ChannelStateView_d35b7681 { key: ChannelFullName! value: ChannelStateView! } @@ -365,7 +365,7 @@ type Entry_ChannelFullName_ChannelStateView_84ad3897 { """ A GraphQL-visible map item, complete with key. """ -type Entry_Origin_InboxStateView_7fb40df6 { +type Entry_Origin_InboxStateView_7865682b { key: Origin! value: InboxStateView! } @@ -381,7 +381,7 @@ type Entry_Owner_Amount_771b9c6c { """ A GraphQL-visible map item, complete with key. """ -type Entry_Target_OutboxStateView_bc6210d6 { +type Entry_Target_OutboxStateView_9fdb7825 { key: Target! value: OutboxStateView! } @@ -459,12 +459,12 @@ type InboxStateView { """ These bundles have been added and are waiting to be removed. """ - addedBundles: QueueView_MessageBundle_86d6cf45! + addedBundles: QueueView_MessageBundle_f06b78bb! """ These bundles have been removed by anticipation and are waiting to be added. At least one of `added_bundles` and `removed_bundles` should be empty. """ - removedBundles: QueueView_MessageBundle_86d6cf45! + removedBundles: QueueView_MessageBundle_f06b78bb! } """ @@ -491,15 +491,15 @@ A scalar that can represent any JSON Object value. """ scalar JSONObject -type LogView_BlockHeight_db6bcc27 { +type LogView_BlockHeight_be3af4a4 { entries(start: Int, end: Int): [BlockHeight!]! } -type LogView_ChainAndHeight_c25ecaa6 { +type LogView_ChainAndHeight_74e1b2c7 { entries(start: Int, end: Int): [ChainAndHeight!]! } -type LogView_CryptoHash_20eccc8d { +type LogView_CryptoHash_b39baa6c { entries(start: Int, end: Int): [CryptoHash!]! } @@ -535,7 +535,7 @@ input MapInput_Target_16f15470 { filters: MapFilters_Target_6fda9ea4 } -type MapView_Owner_Amount_798b2a71 { +type MapView_Owner_Amount_6d9470be { keys(count: Int): [Owner!]! entry(key: Owner!): Entry_Owner_Amount_771b9c6c! entries(input: MapInput_Owner_2b9cd89a): [Entry_Owner_Amount_771b9c6c!]! @@ -718,7 +718,7 @@ type OutboxStateView { Keep sending these certified blocks of ours until they are acknowledged by receivers. """ - queue: QueueView_BlockHeight_ebfa8266! + queue: QueueView_BlockHeight_729b63dd! } """ @@ -773,15 +773,15 @@ type QueryRoot { version: VersionInfo! } -type QueueView_BlockHeight_ebfa8266 { +type QueueView_BlockHeight_729b63dd { entries(count: Int): [BlockHeight!]! } -type QueueView_MessageBundle_86d6cf45 { +type QueueView_MessageBundle_f06b78bb { entries(count: Int): [MessageBundle!]! } -type QueueView_TimestampedBundleInInbox_cdcf52b8 { +type QueueView_TimestampedBundleInInbox_f9f36704 { entries(count: Int): [TimestampedBundleInInbox!]! } @@ -790,22 +790,22 @@ The recipient of a transfer """ scalar Recipient -type ReentrantCollectionView_ChannelFullName_ChannelStateView_4201533849 { +type ReentrantCollectionView_ChannelFullName_ChannelStateView_394492371 { keys: [ChannelFullName!]! - entry(key: ChannelFullName!): Entry_ChannelFullName_ChannelStateView_84ad3897! - entries(input: MapInput_ChannelFullName_3aa4320a): [Entry_ChannelFullName_ChannelStateView_84ad3897!]! + entry(key: ChannelFullName!): Entry_ChannelFullName_ChannelStateView_d35b7681! + entries(input: MapInput_ChannelFullName_3aa4320a): [Entry_ChannelFullName_ChannelStateView_d35b7681!]! } -type ReentrantCollectionView_Origin_InboxStateView_3485213288 { +type ReentrantCollectionView_Origin_InboxStateView_1712852561 { keys: [Origin!]! - entry(key: Origin!): Entry_Origin_InboxStateView_7fb40df6! - entries(input: MapInput_Origin_08662377): [Entry_Origin_InboxStateView_7fb40df6!]! + entry(key: Origin!): Entry_Origin_InboxStateView_7865682b! + entries(input: MapInput_Origin_08662377): [Entry_Origin_InboxStateView_7865682b!]! } -type ReentrantCollectionView_Target_OutboxStateView_4197956612 { +type ReentrantCollectionView_Target_OutboxStateView_2644302559 { keys: [Target!]! - entry(key: Target!): Entry_Target_OutboxStateView_bc6210d6! - entries(input: MapInput_Target_16f15470): [Entry_Target_OutboxStateView_bc6210d6!]! + entry(key: Target!): Entry_Target_OutboxStateView_9fdb7825! + entries(input: MapInput_Target_16f15470): [Entry_Target_OutboxStateView_9fdb7825!]! } """ @@ -911,7 +911,7 @@ type SystemExecutionStateView { committees: JSONObject! ownership: ChainOwnership! balance: Amount! - balances: MapView_Owner_Amount_798b2a71! + balances: MapView_Owner_Amount_6d9470be! timestamp: Timestamp! } diff --git a/linera-service/template/contract.rs.template b/linera-service/template/contract.rs.template index dda714d2d305..19e50c930a1b 100644 --- a/linera-service/template/contract.rs.template +++ b/linera-service/template/contract.rs.template @@ -27,7 +27,7 @@ impl Contract for ApplicationContract {{ type InstantiationArgument = (); async fn load(runtime: ContractRuntime) -> Self {{ - let state = Application::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Application::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); ApplicationContract {{ state, runtime }} diff --git a/linera-service/template/service.rs.template b/linera-service/template/service.rs.template index c30f0bc0ce73..966ff1a0677c 100644 --- a/linera-service/template/service.rs.template +++ b/linera-service/template/service.rs.template @@ -24,7 +24,7 @@ impl Service for ApplicationService {{ type Parameters = (); async fn new(runtime: ServiceRuntime) -> Self {{ - let state = Application::load(ViewStorageContext::from(runtime.key_value_store())) + let state = Application::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); ApplicationService {{ state, runtime }} diff --git a/linera-storage/src/db_storage.rs b/linera-storage/src/db_storage.rs index 6ba3e4da60a5..3eacd3d11586 100644 --- a/linera-storage/src/db_storage.rs +++ b/linera-storage/src/db_storage.rs @@ -23,7 +23,7 @@ use linera_execution::{ use linera_views::{ batch::Batch, common::KeyValueStore, - context::ContextFromStore, + context::ViewContext, value_splitting::DatabaseConsistencyError, views::{View, ViewError}, }; @@ -345,7 +345,7 @@ where Store::Error: From + From + Send + Sync + serde::ser::StdError, { - type Context = ContextFromStore, Store>; + type Context = ViewContext, Store>; type Clock = C; fn clock(&self) -> &C { @@ -367,7 +367,7 @@ where }; let root_key = bcs::to_bytes(&BaseKey::ChainState(chain_id))?; let store = self.store.clone_with_root_key(&root_key)?; - let context = ContextFromStore::create(store, runtime_context).await?; + let context = ViewContext::create_root_context(store, runtime_context).await?; ChainStateView::load(context).await } diff --git a/linera-views/README.md b/linera-views/README.md index af984bf71300..76b6fd8bff44 100644 --- a/linera-views/README.md +++ b/linera-views/README.md @@ -21,7 +21,7 @@ We provide support for the following databases: * `ScyllaDbStore` is a cloud-based Cassandra-compatible database. * `ServiceStoreClient` is a gRPC-based storage that uses either memory or RocksDB. It is available in `linera-storage-service`. -The corresponding trait in the code is the [`common::KeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.KeyValueStore.html). +The corresponding trait in the code is the [`crate::common::KeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.KeyValueStore.html). The trait decomposes into a [`common::ReadableKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.ReadableKeyValueStore.html) and a [`common::WritableKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.WritableKeyValueStore.html). In addition, there is a [`common::AdminKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.AdminKeyValueStore.html) diff --git a/linera-views/benches/reentrant_collection_view.rs b/linera-views/benches/reentrant_collection_view.rs index 139430d81252..a45c33c691df 100644 --- a/linera-views/benches/reentrant_collection_view.rs +++ b/linera-views/benches/reentrant_collection_view.rs @@ -6,8 +6,7 @@ use std::time::{Duration, Instant}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use linera_views::{ batch::Batch, - context::Context, - memory::{create_test_memory_context, MemoryContext}, + context::{create_test_memory_context, Context, MemoryContext}, reentrant_collection_view::ReentrantCollectionView, register_view::RegisterView, views::View, diff --git a/linera-views/src/backends/dynamo_db.rs b/linera-views/src/backends/dynamo_db.rs index deca61c7a752..d8009e984ec5 100644 --- a/linera-views/src/backends/dynamo_db.rs +++ b/linera-views/src/backends/dynamo_db.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Implements [`crate::common::KeyValueStore`] for the DynamoDB database. + use std::{collections::HashMap, env, sync::Arc}; use async_lock::{Semaphore, SemaphoreGuard}; @@ -44,7 +46,6 @@ use crate::{ AdminKeyValueStore, CommonStoreConfig, KeyIterable, KeyValueIterable, KeyValueStoreError, ReadableKeyValueStore, WithError, WritableKeyValueStore, }, - context::ContextFromStore, journaling::{DirectWritableKeyValueStore, JournalConsistencyError, JournalingKeyValueStore}, lru_caching::{LruCachingStore, TEST_CACHE_SIZE}, value_splitting::{DatabaseConsistencyError, ValueSplittingStore}, @@ -1107,11 +1108,6 @@ impl DynamoDbStore { } } -/// An implementation of [`Context`][trait1] based on [`DynamoDbStore`]. -/// -/// [trait1]: crate::context::Context -pub type DynamoDbContext = ContextFromStore; - /// Error when validating a table name. #[derive(Debug, Error)] pub enum InvalidTableName { @@ -1128,7 +1124,7 @@ pub enum InvalidTableName { InvalidCharacter, } -/// Errors that occur when using [`DynamoDbContext`]. +/// Errors that occur when using [`DynamoDbStore`]. #[derive(Debug, Error)] pub enum DynamoDbStoreError { /// An error occurred while getting the item. diff --git a/linera-views/src/backends/indexed_db.rs b/linera-views/src/backends/indexed_db.rs index 604c7efd68cd..d3e8b181e1e0 100644 --- a/linera-views/src/backends/indexed_db.rs +++ b/linera-views/src/backends/indexed_db.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Implements [`crate::common::KeyValueStore`] for the IndexedDB Web database. + use std::{fmt::Debug, rc::Rc}; use futures::future; @@ -13,7 +15,6 @@ use crate::{ get_upper_bound_option, CommonStoreConfig, KeyValueStoreError, LocalAdminKeyValueStore, LocalReadableKeyValueStore, LocalWritableKeyValueStore, WithError, }, - context::ContextFromStore, value_splitting::DatabaseConsistencyError, }; @@ -309,24 +310,11 @@ impl LocalAdminKeyValueStore for IndexedDbStore { } } -/// An implementation of [`crate::context::Context`] that stores all values in an IndexedDB -/// database. -pub type IndexedDbContext = ContextFromStore; - #[cfg(with_testing)] mod testing { use super::*; use crate::test_utils::generate_test_namespace; - /// Provides a `IndexedDbContext<()>` that can be used for tests. - pub async fn create_indexed_db_test_context() -> IndexedDbContext<()> { - IndexedDbContext::new_unsafe( - create_indexed_db_store_stream_queries(TEST_INDEX_DB_MAX_STREAM_QUERIES).await, - Vec::new(), - (), - ) - } - /// Creates a test IndexedDB client for working. pub async fn create_indexed_db_store_stream_queries( max_stream_queries: usize, @@ -349,7 +337,7 @@ mod testing { #[cfg(with_testing)] pub use testing::*; -/// The error type for [`IndexedDbContext`]. +/// The error type for [`IndexedDbStore`]. #[derive(Error, Debug)] pub enum IndexedDbStoreError { /// Serialization error with BCS. diff --git a/linera-views/src/backends/journaling.rs b/linera-views/src/backends/journaling.rs index a5665f687a1d..33ac86f5b2d8 100644 --- a/linera-views/src/backends/journaling.rs +++ b/linera-views/src/backends/journaling.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Turns a `DirectKeyValueStore` into a `KeyValueStore` by adding journaling. +//! //! Journaling aims to allow writing arbitrarily large batches of data in an atomic way. //! This is useful for database backends that limit the number of keys and/or the size of //! the data that can be written atomically (i.e. in the same database transaction). diff --git a/linera-views/src/backends/lru_caching.rs b/linera-views/src/backends/lru_caching.rs index 930a7e1df144..1206d4df9fb8 100644 --- a/linera-views/src/backends/lru_caching.rs +++ b/linera-views/src/backends/lru_caching.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Add LRU (least recently used) caching to a given store. + /// The standard cache size used for tests. pub const TEST_CACHE_SIZE: usize = 1000; @@ -14,9 +16,9 @@ use std::{ use linked_hash_map::LinkedHashMap; #[cfg(with_metrics)] use prometheus::{register_int_counter_vec, IntCounterVec}; -#[cfg(with_testing)] -use {crate::context::ContextFromStore, crate::memory::MemoryStore}; +#[cfg(with_testing)] +use crate::memory::MemoryStore; use crate::{ batch::{Batch, WriteOperation}, common::{ @@ -296,33 +298,6 @@ where } } -/// A context that stores all values in memory. -#[cfg(with_testing)] -pub type LruCachingMemoryContext = ContextFromStore>; - -/* +/// A memory store with caching. #[cfg(with_testing)] -impl LruCachingMemoryContext { - /// Creates a [`crate::key_value_store_view::KeyValueStoreMemoryContext`]. - pub async fn new(extra: E, cache_size: usize) -> Result { - let common_config = CommonStoreConfig { - max_concurrent_queries: None, - max_stream_queries: TEST_MEMORY_MAX_STREAM_QUERIES, - cache_size, - }; - let config = MemoryStoreConfig { common_config }; - let namespace = "linera"; - let root_key = &[]; - let store = MemoryStore::maybe_create_and_connect(&config, namespace, root_key) - .await - .expect("store"); - let store = LruCachingStore::new(store, cache_size); - let base_key = Vec::new(); - Ok(Self { - store, - base_key, - extra, - }) - } -} -*/ +pub type LruCachingMemoryStore = LruCachingStore; diff --git a/linera-views/src/backends/memory.rs b/linera-views/src/backends/memory.rs index 836d8f6854a9..1686007ab764 100644 --- a/linera-views/src/backends/memory.rs +++ b/linera-views/src/backends/memory.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Implements [`crate::common::KeyValueStore`] in memory. + use std::{ collections::BTreeMap, fmt::Debug, @@ -12,12 +14,11 @@ use thiserror::Error; #[cfg(with_testing)] use crate::test_utils::generate_test_namespace; use crate::{ - batch::{Batch, DeletePrefixExpander, WriteOperation}, + batch::{Batch, WriteOperation}, common::{ - get_interval, AdminKeyValueStore, CommonStoreConfig, KeyIterable, KeyValueStoreError, + get_interval, AdminKeyValueStore, CommonStoreConfig, KeyValueStoreError, ReadableKeyValueStore, WithError, WritableKeyValueStore, }, - context::{Context, ContextFromStore}, value_splitting::DatabaseConsistencyError, }; @@ -374,9 +375,6 @@ impl AdminKeyValueStore for MemoryStore { } } -/// An implementation of [`crate::context::Context`] that stores all values in memory. -pub type MemoryContext = ContextFromStore; - /// Creates a default memory test config pub fn create_memory_store_test_config() -> MemoryStoreConfig { let max_stream_queries = TEST_MEMORY_MAX_STREAM_QUERIES; @@ -388,16 +386,6 @@ pub fn create_memory_store_test_config() -> MemoryStoreConfig { MemoryStoreConfig { common_config } } -/// Provides a `MemoryContext<()>` that can be used for tests. -/// It is not named create_memory_test_context because it is massively -/// used and so we want to have a short name. -#[cfg(with_testing)] -pub fn create_test_memory_context() -> MemoryContext<()> { - let namespace = generate_test_namespace(); - let root_key = &[]; - MemoryContext::new_for_testing(TEST_MEMORY_MAX_STREAM_QUERIES, &namespace, root_key, ()) -} - /// Creates a test memory store for working. #[cfg(with_testing)] pub fn create_test_memory_store() -> MemoryStore { @@ -406,7 +394,7 @@ pub fn create_test_memory_store() -> MemoryStore { MemoryStore::new_for_testing(TEST_MEMORY_MAX_STREAM_QUERIES, &namespace, root_key).unwrap() } -/// The error type for [`MemoryContext`]. +/// The error type for [`MemoryStore`]. #[derive(Error, Debug)] pub enum MemoryStoreError { /// Serialization error with BCS. @@ -429,17 +417,3 @@ pub enum MemoryStoreError { impl KeyValueStoreError for MemoryStoreError { const BACKEND: &'static str = "memory"; } - -impl DeletePrefixExpander for MemoryContext<()> { - type Error = MemoryStoreError; - - async fn expand_delete_prefix(&self, key_prefix: &[u8]) -> Result>, Self::Error> { - let mut vector_list = Vec::new(); - for key in > as KeyIterable>::iterator( - &self.find_keys_by_prefix(key_prefix).await?, - ) { - vector_list.push(key?.to_vec()); - } - Ok(vector_list) - } -} diff --git a/linera-views/src/backends/metering.rs b/linera-views/src/backends/metering.rs index 1b4d85ca8901..84435298503b 100644 --- a/linera-views/src/backends/metering.rs +++ b/linera-views/src/backends/metering.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Adds metrics to a key-value store. + use std::sync::LazyLock; use convert_case::{Case, Casing}; diff --git a/linera-views/src/backends/mod.rs b/linera-views/src/backends/mod.rs index ebc653914f5b..55a19481b5b3 100644 --- a/linera-views/src/backends/mod.rs +++ b/linera-views/src/backends/mod.rs @@ -1,34 +1,25 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -/// The code to turn a `DirectKeyValueStore` into a `KeyValueStore` by adding journaling. pub mod journaling; -/// The code for encapsulating one key_value store into another that does metric #[cfg(with_metrics)] pub mod metering; -/// The code for handling big values by splitting them into several small ones. pub mod value_splitting; -/// Helper definitions for in-memory storage. pub mod memory; -/// The LRU (least recently used) caching. pub mod lru_caching; -/// A storage backend for views based on ScyllaDB #[cfg(with_scylladb)] pub mod scylla_db; -/// A storage backend for views based on RocksDB #[cfg(with_rocksdb)] pub mod rocks_db; -/// A storage backend for views based on DynamoDB #[cfg(with_dynamodb)] pub mod dynamo_db; -/// A storage backend for views in the browser based on IndexedDB #[cfg(with_indexeddb)] pub mod indexed_db; diff --git a/linera-views/src/backends/rocks_db.rs b/linera-views/src/backends/rocks_db.rs index f33fa179e988..fefdf9c8c1fc 100644 --- a/linera-views/src/backends/rocks_db.rs +++ b/linera-views/src/backends/rocks_db.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Implements [`crate::common::KeyValueStore`] for the RocksDB database. + use std::{ collections::{btree_map::Entry, BTreeMap}, ffi::OsString, @@ -26,7 +28,6 @@ use crate::{ get_upper_bound, AdminKeyValueStore, CommonStoreConfig, KeyValueStoreError, ReadableKeyValueStore, WithError, WritableKeyValueStore, }, - context::ContextFromStore, lru_caching::{LruCachingStore, TEST_CACHE_SIZE}, value_splitting::{DatabaseConsistencyError, ValueSplittingStore}, }; @@ -501,9 +502,6 @@ pub async fn create_rocks_db_test_store() -> RocksDbStore { .expect("store") } -/// An implementation of [`crate::context::Context`] based on RocksDB -pub type RocksDbContext = ContextFromStore; - impl RocksDbStore { #[cfg(with_metrics)] fn inner(&self) -> &RocksDbStoreInternal { @@ -631,7 +629,7 @@ impl AdminKeyValueStore for RocksDbStore { } } -/// The error type for [`RocksDbContext`] +/// The error type for [`RocksDbStore`] #[derive(Error, Debug)] pub enum RocksDbStoreError { /// Tokio join error in RocksDb. diff --git a/linera-views/src/backends/scylla_db.rs b/linera-views/src/backends/scylla_db.rs index 2b73ac678439..07289d9bb22f 100644 --- a/linera-views/src/backends/scylla_db.rs +++ b/linera-views/src/backends/scylla_db.rs @@ -1,12 +1,11 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -//! This provides a `KeyValueStore for the ScyllaDB database. -//! The code is functional but some aspects are missing. +//! Implements [`crate::common::KeyValueStore`] for the ScyllaDB database. //! -//! The current connection is done via a Session and a corresponding -//! primary key that we name `namespace`. The maximum number of -//! concurrent queries is controlled by max_concurrent_queries. +//! The current connection is done via a Session and a corresponding primary key called +//! "namespace". The maximum number of concurrent queries is controlled by +//! `max_concurrent_queries`. /// Fundamental constant in ScyllaDB: The maximum size of a multi keys query /// The limit is in reality 100. But we need one entry for the root key. @@ -40,7 +39,6 @@ use crate::{ get_upper_bound_option, AdminKeyValueStore, CommonStoreConfig, KeyValueStoreError, ReadableKeyValueStore, WithError, WritableKeyValueStore, }, - context::ContextFromStore, journaling::{DirectWritableKeyValueStore, JournalConsistencyError, JournalingKeyValueStore}, lru_caching::{LruCachingStore, TEST_CACHE_SIZE}, value_splitting::DatabaseConsistencyError, @@ -948,6 +946,3 @@ pub async fn create_scylla_db_test_store() -> ScyllaDbStore { .await .expect("store") } - -/// An implementation of [`crate::context::Context`] based on ScyllaDB -pub type ScyllaDbContext = ContextFromStore; diff --git a/linera-views/src/backends/value_splitting.rs b/linera-views/src/backends/value_splitting.rs index 8a7c64c0cd1c..0b46302640ae 100644 --- a/linera-views/src/backends/value_splitting.rs +++ b/linera-views/src/backends/value_splitting.rs @@ -1,6 +1,8 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +//! Adds support for large values to a given store by splitting them between several keys. + use std::fmt::Debug; use linera_base::ensure; diff --git a/linera-views/src/batch.rs b/linera-views/src/batch.rs index fd5822b7431d..ee91d0b00bd1 100644 --- a/linera-views/src/batch.rs +++ b/linera-views/src/batch.rs @@ -624,8 +624,7 @@ impl BatchValueWriter for UnorderedBatchIter { mod tests { use linera_views::{ batch::{Batch, SimpleUnorderedBatch, UnorderedBatch}, - context::Context, - memory::create_test_memory_context, + context::{create_test_memory_context, Context}, }; #[test] diff --git a/linera-views/src/context.rs b/linera-views/src/context.rs index 884fc6949132..5f92e92af9e0 100644 --- a/linera-views/src/context.rs +++ b/linera-views/src/context.rs @@ -12,7 +12,7 @@ use serde::{de::DeserializeOwned, Serialize}; use crate::{ backends::memory::MemoryStore, - batch::Batch, + batch::{Batch, DeletePrefixExpander}, common::{ from_bytes_option, KeyIterable, KeyValueIterable, KeyValueStoreError, RestrictedKeyValueStore, MIN_VIEW_TAG, @@ -165,7 +165,7 @@ pub trait Context: Clone { /// Implementation of the [`Context`] trait on top of a DB client implementing /// [`crate::common::KeyValueStore`]. #[derive(Debug, Default, Clone)] -pub struct ContextFromStore { +pub struct ViewContext { /// The DB client that is shared between views. store: S, /// The base key for the context. @@ -174,23 +174,23 @@ pub struct ContextFromStore { extra: E, } -impl ContextFromStore +impl ViewContext where S: RestrictedKeyValueStore, { /// Creates a context suitable for a root view, using the given store. If the /// journal's store is non-empty, it will be cleared first, before the context is /// returned. - pub async fn create(store: S, extra: E) -> Result { + pub async fn create_root_context(store: S, extra: E) -> Result { store.clear_journal().await?; Ok(Self::new_unsafe(store, Vec::new(), extra)) } } -impl ContextFromStore { +impl ViewContext { /// Creates a context for the given base key, store, and an extra argument. NOTE: this /// constructor doesn't check the journal of the store. In doubt, use - /// [`ContextFromStore::create`] instead. + /// [`ViewContext::create_root_context`] instead. pub fn new_unsafe(store: S, base_key: Vec, extra: E) -> Self { Self { store, @@ -226,7 +226,7 @@ where } #[async_trait] -impl Context for ContextFromStore +impl Context for ViewContext where E: Clone + Send + Sync, S: RestrictedKeyValueStore + Clone + Send + Sync, @@ -306,7 +306,23 @@ where } } -impl ContextFromStore { +/// An implementation of [`crate::context::Context`] that stores all values in memory. +pub type MemoryContext = ViewContext; + +/// Provides a `MemoryContext<()>` that can be used for tests. +#[cfg(with_testing)] +pub fn create_test_memory_context() -> MemoryContext<()> { + let namespace = crate::test_utils::generate_test_namespace(); + let root_key = &[]; + MemoryContext::new_for_testing( + crate::memory::TEST_MEMORY_MAX_STREAM_QUERIES, + &namespace, + root_key, + (), + ) +} + +impl MemoryContext { /// Creates a [`Context`] instance in memory for testing. #[cfg(with_testing)] pub fn new_for_testing( @@ -324,3 +340,17 @@ impl ContextFromStore { } } } + +impl DeletePrefixExpander for MemoryContext<()> { + type Error = crate::memory::MemoryStoreError; + + async fn expand_delete_prefix(&self, key_prefix: &[u8]) -> Result>, Self::Error> { + let mut vector_list = Vec::new(); + for key in > as KeyIterable>::iterator( + &self.find_keys_by_prefix(key_prefix).await?, + ) { + vector_list.push(key?.to_vec()); + } + Ok(vector_list) + } +} diff --git a/linera-views/src/lib.rs b/linera-views/src/lib.rs index 2432dcc1078c..36e4abf2e176 100644 --- a/linera-views/src/lib.rs +++ b/linera-views/src/lib.rs @@ -23,7 +23,7 @@ We provide support for the following databases: * `ScyllaDbStore` is a cloud-based Cassandra-compatible database. * `ServiceStoreClient` is a gRPC-based storage that uses either memory or RocksDB. It is available in `linera-storage-service`. -The corresponding trait in the code is the [`common::KeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.KeyValueStore.html). +The corresponding trait in the code is the [`crate::common::KeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.KeyValueStore.html). The trait decomposes into a [`common::ReadableKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.ReadableKeyValueStore.html) and a [`common::WritableKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.WritableKeyValueStore.html). In addition, there is a [`common::AdminKeyValueStore`](https://docs.rs/linera-views/latest/linera_views/common/trait.AdminKeyValueStore.html) @@ -71,7 +71,7 @@ pub mod common; /// Elementary data-structures implementing the [`views::View`] trait. pub mod views; -/// Backend implementing the [`common::KeyValueStore`] trait. +/// Backend implementing the [`crate::common::KeyValueStore`] trait. pub mod backends; /// Support for metrics. diff --git a/linera-views/src/test_utils/test_views.rs b/linera-views/src/test_utils/test_views.rs index 9cebdb328700..b69294caf10d 100644 --- a/linera-views/src/test_utils/test_views.rs +++ b/linera-views/src/test_utils/test_views.rs @@ -10,9 +10,9 @@ use async_trait::async_trait; use crate::{ self as linera_views, collection_view::CollectionView, + context::MemoryContext, log_view::LogView, map_view::MapView, - memory::MemoryContext, register_view::RegisterView, views::{ClonableView, RootView, ViewError}, }; diff --git a/linera-views/src/views/collection_view.rs b/linera-views/src/views/collection_view.rs index 45a029fe4d15..a048930ad62e 100644 --- a/linera-views/src/views/collection_view.rs +++ b/linera-views/src/views/collection_view.rs @@ -216,10 +216,10 @@ where /// can be modified. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -237,10 +237,10 @@ where /// is read-only. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -259,10 +259,10 @@ where /// May fail if one subview is already being visited. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -323,10 +323,10 @@ where /// Resets an entry to the default value. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -354,10 +354,10 @@ where /// Tests if the collection contains a specified key and returns a boolean. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -385,10 +385,10 @@ where /// Marks the entry as removed. If absent then nothing is done. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -465,10 +465,10 @@ where /// ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -533,10 +533,10 @@ where /// lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -566,10 +566,10 @@ where /// Returns the list of keys in the collection. The order is lexicographic. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::ByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ByteCollectionView<_, RegisterView<_, String>> = /// ByteCollectionView::load(context).await.unwrap(); @@ -738,10 +738,10 @@ where /// can be modified. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -764,10 +764,10 @@ where /// is read-only. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -791,10 +791,10 @@ where /// May fail if one subview is already being visited. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -824,10 +824,10 @@ where /// Resets an entry to the default value. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -852,10 +852,10 @@ where /// Removes an entry from the CollectionView. If absent nothing happens. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -894,10 +894,10 @@ where /// the serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -930,10 +930,10 @@ where /// the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -966,10 +966,10 @@ where /// determined by the serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CollectionView<_, u64, RegisterView<_, String>> = /// CollectionView::load(context).await.unwrap(); @@ -1099,10 +1099,10 @@ where /// can be modified. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1125,10 +1125,10 @@ where /// is read-only. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1152,10 +1152,10 @@ where /// May fail if one subview is already being visited. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1185,10 +1185,10 @@ where /// Marks the entry so that it is removed in the next flush. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1213,10 +1213,10 @@ where /// Removes an entry from the CollectionView. If absent nothing happens. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1254,10 +1254,10 @@ where /// Returns the list of indices in the collection in the order determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1290,10 +1290,10 @@ where /// then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); @@ -1327,10 +1327,10 @@ where /// determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::collection_view::CustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> = /// CustomCollectionView::load(context).await.unwrap(); diff --git a/linera-views/src/views/key_value_store_view.rs b/linera-views/src/views/key_value_store_view.rs index 4635c55ab169..d37041aae24a 100644 --- a/linera-views/src/views/key_value_store_view.rs +++ b/linera-views/src/views/key_value_store_view.rs @@ -43,8 +43,6 @@ static KEY_VALUE_STORE_VIEW_HASH_RUNTIME: LazyLock = LazyLock::new #[cfg(with_testing)] use { crate::common::{KeyValueStoreError, ReadableKeyValueStore, WithError, WritableKeyValueStore}, - crate::context::ContextFromStore, - crate::memory::MemoryContext, async_lock::RwLock, std::sync::Arc, thiserror::Error, @@ -309,9 +307,9 @@ where /// Getting the total sizes that will be used for keys and values when stored /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::{KeyValueStoreView, SizeData}; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// let total_size = view.total_size(); @@ -326,9 +324,9 @@ where /// false, then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -398,9 +396,9 @@ where /// Applies the function f over all indices. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -431,9 +429,9 @@ where /// If the function f returns false then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -502,9 +500,9 @@ where /// Applies the function f over all index/value pairs. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -533,9 +531,9 @@ where /// Returns the list of indices in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -557,9 +555,9 @@ where /// Returns the list of indices and values in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -581,9 +579,9 @@ where /// Returns the number of entries. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![0]).await.unwrap(); @@ -605,9 +603,9 @@ where /// Obtains the value at the given index, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![42]).await.unwrap(); @@ -634,9 +632,9 @@ where /// Tests whether the store contains a specific index. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![42]).await.unwrap(); @@ -663,9 +661,9 @@ where /// Tests whether the view contains a range of indices /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![42]).await.unwrap(); @@ -705,9 +703,9 @@ where /// Obtains the values of a range of indices /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![42]).await.unwrap(); @@ -751,10 +749,10 @@ where /// Applies the given batch of `crate::common::WriteOperation`. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; /// # use linera_views::batch::Batch; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -835,9 +833,9 @@ where /// Sets or inserts a value. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -853,9 +851,9 @@ where /// Removes a value. If absent then the action has no effect. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -872,9 +870,9 @@ where /// Deletes a key_prefix. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -891,9 +889,9 @@ where /// Iterates over all the keys matching the given prefix. The prefix is not included in the returned keys. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -962,9 +960,9 @@ where /// prefix is not included in the returned keys. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::key_value_store_view::KeyValueStoreView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view = KeyValueStoreView::load(context).await.unwrap(); /// view.insert(vec![0, 1], vec![34]).await.unwrap(); @@ -1207,7 +1205,3 @@ where Ok(Self { view }) } } - -/// A context that stores all values in memory. -#[cfg(with_testing)] -pub type KeyValueStoreMemoryContext = ContextFromStore>>; diff --git a/linera-views/src/views/log_view.rs b/linera-views/src/views/log_view.rs index a02ee96d0814..30d913bbf9ea 100644 --- a/linera-views/src/views/log_view.rs +++ b/linera-views/src/views/log_view.rs @@ -155,9 +155,9 @@ where /// Pushes a value to the end of the log. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::log_view::LogView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut log = LogView::load(context).await.unwrap(); /// log.push(34); @@ -170,9 +170,9 @@ where /// Reads the size of the log. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::log_view::LogView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut log = LogView::load(context).await.unwrap(); /// log.push(34); @@ -203,9 +203,9 @@ where /// Reads the logged value with the given index (including staged ones). /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::log_view::LogView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut log = LogView::load(context).await.unwrap(); /// log.push(34); @@ -227,9 +227,9 @@ where /// Reads several logged keys (including staged ones) /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::log_view::LogView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut log = LogView::load(context).await.unwrap(); /// log.push(34); @@ -289,9 +289,9 @@ where /// Reads the logged values in the given range (including staged ones). /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::log_view::LogView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut log = LogView::load(context).await.unwrap(); /// log.push(34); diff --git a/linera-views/src/views/map_view.rs b/linera-views/src/views/map_view.rs index c6c29844589d..50d9044447dd 100644 --- a/linera-views/src/views/map_view.rs +++ b/linera-views/src/views/map_view.rs @@ -165,9 +165,9 @@ where /// Inserts or resets the value of a key of the map. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -181,9 +181,9 @@ where /// Removes a value. If absent then nothing is done. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], "Hello"); @@ -202,9 +202,9 @@ where /// Removes a value. If absent then nothing is done. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -233,9 +233,9 @@ where /// Returns `true` if the map contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -268,9 +268,9 @@ where /// Reads the value at the given position, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -295,9 +295,9 @@ where /// Reads the values at the given positions, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -331,9 +331,9 @@ where /// Obtains a mutable reference to a value at a given position if available. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -374,9 +374,9 @@ where /// function and if it returns false, then the loop exits /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -451,9 +451,9 @@ where /// lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -488,9 +488,9 @@ where /// Returns the list of keys of the map in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -520,9 +520,9 @@ where /// in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -553,9 +553,9 @@ where /// Returns the number of keys of the map /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -584,9 +584,9 @@ where /// prematurely /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -672,9 +672,9 @@ where /// lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -717,9 +717,9 @@ where /// in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![1, 2], String::from("Hello")); @@ -753,9 +753,9 @@ where /// Returns the list of keys and values of the map in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![1, 2], String::from("Hello")); @@ -780,9 +780,9 @@ where /// Default value if the index is missing. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::ByteMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = ByteMapView::load(context).await.unwrap(); /// map.insert(vec![0, 1], String::from("Hello")); @@ -934,9 +934,9 @@ where /// Inserts or resets a value at an index. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u32, _> = MapView::load(context).await.unwrap(); /// map.insert(&(24 as u32), String::from("Hello")); @@ -959,9 +959,9 @@ where /// Removes a value. If absent then the operation does nothing. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = MapView::<_, u32, String>::load(context).await.unwrap(); /// map.remove(&(37 as u32)); @@ -986,9 +986,9 @@ where /// Returns `true` if the map contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = MapView::<_, u32, String>::load(context).await.unwrap(); /// map.insert(&(37 as u32), String::from("Hello")); @@ -1016,9 +1016,9 @@ where /// Reads the value at the given position, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u32, _> = MapView::load(context).await.unwrap(); /// map.insert(&(37 as u32), String::from("Hello")); @@ -1041,9 +1041,9 @@ where /// Obtains a mutable reference to a value at a given position if available /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u32, String> = MapView::load(context).await.unwrap(); /// map.insert(&(37 as u32), String::from("Hello")); @@ -1076,9 +1076,9 @@ where /// Returns the list of indices in the map. The order is determined by serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u32, String> = MapView::load(context).await.unwrap(); /// map.insert(&(37 as u32), String::from("Hello")); @@ -1100,9 +1100,9 @@ where /// the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u128, String> = MapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Thanks")); @@ -1139,9 +1139,9 @@ where /// determined by serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u128, String> = MapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1177,9 +1177,9 @@ where /// If the function returns false, then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u128, String> = MapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Thanks")); @@ -1217,9 +1217,9 @@ where /// visited in an order determined by serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, Vec, _> = MapView::load(context).await.unwrap(); /// map.insert(&vec![0, 1], String::from("Hello")); @@ -1263,9 +1263,9 @@ where /// Default value if the index is missing. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u32, u128> = MapView::load(context).await.unwrap(); /// let value = map.get_mut_or_default(&(34 as u32)).await.unwrap(); @@ -1379,9 +1379,9 @@ where /// Insert or resets a value. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u128, _> = MapView::load(context).await.unwrap(); /// map.insert(&(24 as u128), String::from("Hello")); @@ -1404,9 +1404,9 @@ where /// Removes a value. If absent then this does not do anything. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = MapView::<_, u128, String>::load(context).await.unwrap(); /// map.remove(&(37 as u128)); @@ -1431,9 +1431,9 @@ where /// Returns `true` if the map contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = MapView::<_, u128, String>::load(context).await.unwrap(); /// map.insert(&(37 as u128), String::from("Hello")); @@ -1461,10 +1461,9 @@ where /// Reads the value at the given position, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::map_view::CustomMapView; - /// # use linera_views::memory::MemoryContext; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: CustomMapView, u128, String> = /// CustomMapView::load(context).await.unwrap(); @@ -1487,9 +1486,9 @@ where /// Obtains a mutable reference to a value at a given position if available /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: CustomMapView<_, u128, String> = CustomMapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1522,9 +1521,9 @@ where /// by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::MapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: MapView<_, u128, String> = MapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1547,9 +1546,9 @@ where /// then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = CustomMapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1585,9 +1584,9 @@ where /// determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = CustomMapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1624,9 +1623,9 @@ where /// If the function returns false, then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map = CustomMapView::<_, u128, String>::load(context) /// .await @@ -1665,9 +1664,9 @@ where /// visited in an order determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: CustomMapView<_, u128, String> = CustomMapView::load(context).await.unwrap(); /// map.insert(&(34 as u128), String::from("Hello")); @@ -1712,9 +1711,9 @@ where /// Default value if the index is missing. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::map_view::CustomMapView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut map: CustomMapView<_, u128, String> = CustomMapView::load(context).await.unwrap(); /// assert_eq!( diff --git a/linera-views/src/views/queue_view.rs b/linera-views/src/views/queue_view.rs index 6d45257a3311..ee9e51d8024a 100644 --- a/linera-views/src/views/queue_view.rs +++ b/linera-views/src/views/queue_view.rs @@ -194,9 +194,9 @@ where /// Reads the front value, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -217,9 +217,9 @@ where /// Reads the back value, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -238,9 +238,9 @@ where /// Deletes the front value, if any. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34 as u128); @@ -259,9 +259,9 @@ where /// Pushes a value to the end of the queue. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -276,9 +276,9 @@ where /// Reads the size of the queue. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -316,9 +316,9 @@ where /// Reads the `count` next values in the queue (including staged ones). /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -356,9 +356,9 @@ where /// Reads the `count` last values in the queue (including staged ones). /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -392,9 +392,9 @@ where /// Reads all the elements /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); @@ -429,9 +429,9 @@ where /// Gets a mutable iterator on the entries of the queue /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::queue_view::QueueView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut queue = QueueView::load(context).await.unwrap(); /// queue.push_back(34); diff --git a/linera-views/src/views/reentrant_collection_view.rs b/linera-views/src/views/reentrant_collection_view.rs index f9f07470fe03..154830d1bc85 100644 --- a/linera-views/src/views/reentrant_collection_view.rs +++ b/linera-views/src/views/reentrant_collection_view.rs @@ -326,10 +326,10 @@ where /// can be modified. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -354,10 +354,10 @@ where /// If an entry is absent then `None` is returned. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -385,10 +385,10 @@ where /// Returns `true` if the collection contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -416,10 +416,10 @@ where /// Removes an entry. If absent then nothing happens. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -444,10 +444,10 @@ where /// Marks the entry so that it is removed in the next flush. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -491,10 +491,10 @@ where /// The entries in `short_keys` have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -580,10 +580,10 @@ where /// The entries in short_keys have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -667,10 +667,10 @@ where /// Loads all the entries for reading at once. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -743,10 +743,10 @@ where /// Loads all the entries for writing at once. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -822,10 +822,10 @@ where /// Returns the list of indices in the collection in lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -850,10 +850,10 @@ where /// ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -917,10 +917,10 @@ where /// lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantByteCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantByteCollectionView<_, RegisterView<_, String>> = /// ReentrantByteCollectionView::load(context).await.unwrap(); @@ -1112,10 +1112,10 @@ where /// then be modified. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1140,10 +1140,10 @@ where /// If an entry is absent then `None` is returned. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1170,10 +1170,10 @@ where /// Returns `true` if the collection contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1194,10 +1194,10 @@ where /// Marks the entry so that it is removed in the next flush. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1222,10 +1222,10 @@ where /// Marks the entry so that it is removed in the next flush. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1266,10 +1266,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1300,10 +1300,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1336,10 +1336,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1371,10 +1371,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1414,10 +1414,10 @@ where /// by serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1442,10 +1442,10 @@ where /// the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1478,10 +1478,10 @@ where /// determined by the serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCollectionView<_, u64, RegisterView<_, String>> = /// ReentrantCollectionView::load(context).await.unwrap(); @@ -1611,10 +1611,10 @@ where /// is absent then a default entry is put in the collection on this index. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1639,10 +1639,10 @@ where /// If an entry is absent then `None` is returned. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1669,10 +1669,10 @@ where /// Returns `true` if the collection contains a value for the specified key. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1693,10 +1693,10 @@ where /// Removes an entry. If absent then nothing happens. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1721,10 +1721,10 @@ where /// Marks the entry so that it is removed in the next flush. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1767,10 +1767,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1801,10 +1801,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1837,10 +1837,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1872,10 +1872,10 @@ where /// The entries in indices have to be all distinct. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1913,10 +1913,10 @@ where /// the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1941,10 +1941,10 @@ where /// then the loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); @@ -1978,10 +1978,10 @@ where /// determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::{create_test_memory_context, MemoryContext}; + /// # use linera_views::context::{create_test_memory_context, MemoryContext}; /// # use linera_views::reentrant_collection_view::ReentrantCustomCollectionView; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> = /// ReentrantCustomCollectionView::load(context).await.unwrap(); diff --git a/linera-views/src/views/register_view.rs b/linera-views/src/views/register_view.rs index 1ca322b17750..e8bc24c8151b 100644 --- a/linera-views/src/views/register_view.rs +++ b/linera-views/src/views/register_view.rs @@ -135,9 +135,9 @@ where /// Access the current value in the register. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut register = RegisterView::<_, u32>::load(context).await.unwrap(); /// let value = register.get(); @@ -154,9 +154,9 @@ where /// Sets the value in the register. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut register = RegisterView::load(context).await.unwrap(); /// register.set(5); @@ -183,9 +183,9 @@ where /// Obtains a mutable reference to the value in the register. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::register_view::RegisterView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut register: RegisterView<_, u32> = RegisterView::load(context).await.unwrap(); /// let value = register.get_mut(); diff --git a/linera-views/src/views/set_view.rs b/linera-views/src/views/set_view.rs index 68be9d250641..ab44ee34d4cb 100644 --- a/linera-views/src/views/set_view.rs +++ b/linera-views/src/views/set_view.rs @@ -136,8 +136,8 @@ where /// Insert a value. If already present then it has no effect. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.insert(vec![0, 1]); @@ -151,8 +151,8 @@ where /// Removes a value from the set. If absent then no effect. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.remove(vec![0, 1]); @@ -182,8 +182,8 @@ where /// Returns true if the given index exists in the set. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.insert(vec![0, 1]); @@ -215,8 +215,8 @@ where /// Returns the list of keys in the set. The order is lexicographic. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.insert(vec![0, 1]); @@ -239,8 +239,8 @@ where /// prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.insert(vec![0, 1]); @@ -304,8 +304,8 @@ where /// lexicographic order. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::ByteSetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::ByteSetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = ByteSetView::load(context).await.unwrap(); /// set.insert(vec![0, 1]); @@ -437,9 +437,9 @@ where /// Inserts a value. If already present then no effect. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::SetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = SetView::<_, u32>::load(context).await.unwrap(); /// set.insert(&(34 as u32)); @@ -459,8 +459,8 @@ where /// Removes a value. If absent then nothing is done. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::SetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::SetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = SetView::<_, u32>::load(context).await.unwrap(); /// set.remove(&(34 as u32)); @@ -492,8 +492,8 @@ where /// Returns true if the given index exists in the set. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::SetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::SetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set: SetView<_, u32> = SetView::load(context).await.unwrap(); /// set.insert(&(34 as u32)); @@ -520,8 +520,8 @@ where /// Returns the list of indices in the set. The order is determined by serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::{memory::create_test_memory_context, set_view::SetView}; - /// # use crate::linera_views::views::View; + /// # use linera_views::{context::create_test_memory_context, set_view::SetView}; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set: SetView<_, u32> = SetView::load(context).await.unwrap(); /// set.insert(&(34 as u32)); @@ -543,9 +543,9 @@ where /// loop ends prematurely. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::SetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = SetView::<_, u32>::load(context).await.unwrap(); /// set.insert(&(34 as u32)); @@ -578,9 +578,9 @@ where /// determined by the serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::SetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = SetView::<_, u32>::load(context).await.unwrap(); /// set.insert(&(34 as u32)); @@ -705,9 +705,9 @@ where /// Inserts a value. If present then it has no effect. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.insert(&(34 as u128)); @@ -727,9 +727,9 @@ where /// Removes a value. If absent then nothing is done. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.remove(&(34 as u128)); @@ -761,9 +761,9 @@ where /// Returns true if the given index exists in the set. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.insert(&(34 as u128)); @@ -791,9 +791,9 @@ where /// serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.insert(&(34 as u128)); @@ -816,9 +816,9 @@ where /// false, then the loop prematurely ends. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.insert(&(34 as u128)); @@ -851,9 +851,9 @@ where /// determined by the custom serialization. /// ```rust /// # tokio_test::block_on(async { - /// # use linera_views::memory::create_test_memory_context; + /// # use linera_views::context::create_test_memory_context; /// # use linera_views::set_view::CustomSetView; - /// # use crate::linera_views::views::View; + /// # use linera_views::views::View; /// # let context = create_test_memory_context(); /// let mut set = CustomSetView::<_, u128>::load(context).await.unwrap(); /// set.insert(&(34 as u128)); diff --git a/linera-views/src/views/unit_tests/views.rs b/linera-views/src/views/unit_tests/views.rs index 384d1bb2e918..83723ba1d77f 100644 --- a/linera-views/src/views/unit_tests/views.rs +++ b/linera-views/src/views/unit_tests/views.rs @@ -9,17 +9,15 @@ use test_case::test_case; #[cfg(with_dynamodb)] use crate::dynamo_db::{ - create_dynamo_db_common_config, DynamoDbContext, DynamoDbStore, DynamoDbStoreConfig, - LocalStackTestContext, + create_dynamo_db_common_config, DynamoDbStore, DynamoDbStoreConfig, LocalStackTestContext, }; #[cfg(with_rocksdb)] -use crate::rocks_db::{RocksDbContext, RocksDbStore}; +use crate::rocks_db::RocksDbStore; #[cfg(with_scylladb)] -use crate::scylla_db::{ScyllaDbContext, ScyllaDbStore}; +use crate::scylla_db::ScyllaDbStore; use crate::{ batch::Batch, - context::Context, - memory::{create_test_memory_context, MemoryContext}, + context::{create_test_memory_context, Context, MemoryContext}, queue_view::QueueView, reentrant_collection_view::ReentrantCollectionView, register_view::{HashedRegisterView, RegisterView}, @@ -29,7 +27,9 @@ use crate::{ views::{HashableView, View, ViewError}, }; #[cfg(any(with_rocksdb, with_scylladb, with_dynamodb))] -use crate::{common::AdminKeyValueStore, test_utils::generate_test_namespace}; +use crate::{ + common::AdminKeyValueStore, context::ViewContext, test_utils::generate_test_namespace, +}; #[tokio::test] async fn test_queue_operations_with_memory_context() -> Result<(), anyhow::Error> { @@ -213,14 +213,14 @@ struct RocksDbContextFactory {} #[cfg(with_rocksdb)] #[async_trait] impl TestContextFactory for RocksDbContextFactory { - type Context = RocksDbContext<()>; + type Context = ViewContext<(), RocksDbStore>; async fn new_context(&mut self) -> Result { let config = RocksDbStore::new_test_config().await?; let namespace = generate_test_namespace(); let root_key = &[]; let store = RocksDbStore::recreate_and_connect(&config, &namespace, root_key).await?; - let context = RocksDbContext::create(store, ()).await?; + let context = ViewContext::create_root_context(store, ()).await?; Ok(context) } @@ -235,7 +235,7 @@ struct DynamoDbContextFactory { #[cfg(with_dynamodb)] #[async_trait] impl TestContextFactory for DynamoDbContextFactory { - type Context = DynamoDbContext<()>; + type Context = ViewContext<(), DynamoDbStore>; async fn new_context(&mut self) -> Result { if self.localstack.is_none() { @@ -252,7 +252,7 @@ impl TestContextFactory for DynamoDbContextFactory { }; let store = DynamoDbStore::recreate_and_connect(&store_config, &namespace, root_key).await?; - Ok(DynamoDbContext::create(store, ()).await?) + Ok(ViewContext::create_root_context(store, ()).await?) } } @@ -263,14 +263,14 @@ struct ScyllaDbContextFactory; #[cfg(with_scylladb)] #[async_trait] impl TestContextFactory for ScyllaDbContextFactory { - type Context = ScyllaDbContext<()>; + type Context = ViewContext<(), ScyllaDbStore>; async fn new_context(&mut self) -> Result { let config = ScyllaDbStore::new_test_config().await?; let namespace = generate_test_namespace(); let root_key = &[]; let store = ScyllaDbStore::recreate_and_connect(&config, &namespace, root_key).await?; - let context = ScyllaDbContext::create(store, ()).await?; + let context = ViewContext::create_root_context(store, ()).await?; Ok(context) } } diff --git a/linera-views/tests/hashable_tests.rs b/linera-views/tests/hashable_tests.rs index 5b62f646dcbc..b52c9367ff93 100644 --- a/linera-views/tests/hashable_tests.rs +++ b/linera-views/tests/hashable_tests.rs @@ -4,8 +4,8 @@ use anyhow::Result; use linera_views::{ common::HasherOutput, + context::create_test_memory_context, hashable_wrapper::WrappedHashableContainerView, - memory::create_test_memory_context, register_view::{HashedRegisterView, RegisterView}, views::{HashableView, View}, }; diff --git a/linera-views/tests/random_container_tests.rs b/linera-views/tests/random_container_tests.rs index 2477d5564994..aa97234f64e5 100644 --- a/linera-views/tests/random_container_tests.rs +++ b/linera-views/tests/random_container_tests.rs @@ -6,10 +6,9 @@ use std::collections::{BTreeMap, BTreeSet}; use anyhow::Result; use linera_views::{ collection_view::HashedCollectionView, - context::Context, + context::{create_test_memory_context, Context}, key_value_store_view::{KeyValueStoreView, SizeData}, map_view::HashedByteMapView, - memory::create_test_memory_context, queue_view::HashedQueueView, reentrant_collection_view::HashedReentrantCollectionView, register_view::RegisterView, diff --git a/linera-views/tests/store_tests.rs b/linera-views/tests/store_tests.rs index df36ccbbac67..99bf81fca629 100644 --- a/linera-views/tests/store_tests.rs +++ b/linera-views/tests/store_tests.rs @@ -3,9 +3,9 @@ use linera_views::{ batch::Batch, - context::Context as _, + context::{create_test_memory_context, Context as _}, key_value_store_view::ViewContainer, - memory::{create_test_memory_context, create_test_memory_store}, + memory::create_test_memory_store, test_utils::{ self, get_random_test_scenarios, run_big_write_read, run_reads, run_writes_from_blank, run_writes_from_state, diff --git a/linera-views/tests/views_tests.rs b/linera-views/tests/views_tests.rs index 712d3ac9e5f6..d1b04e3733b0 100644 --- a/linera-views/tests/views_tests.rs +++ b/linera-views/tests/views_tests.rs @@ -8,21 +8,21 @@ use async_trait::async_trait; #[cfg(any(with_dynamodb, with_rocksdb, with_scylladb))] use linera_views::common::AdminKeyValueStore as _; #[cfg(with_rocksdb)] -use linera_views::rocks_db::{create_rocks_db_test_store, RocksDbContext, RocksDbStore}; +use linera_views::rocks_db::{create_rocks_db_test_store, RocksDbStore}; #[cfg(with_scylladb)] -use linera_views::scylla_db::{create_scylla_db_test_store, ScyllaDbContext, ScyllaDbStore}; +use linera_views::scylla_db::{create_scylla_db_test_store, ScyllaDbStore}; use linera_views::{ batch::{ Batch, WriteOperation, WriteOperation::{Delete, DeletePrefix, Put}, }, collection_view::HashedCollectionView, - context::Context, - key_value_store_view::{KeyValueStoreMemoryContext, KeyValueStoreView, ViewContainer}, + context::{create_test_memory_context, Context, MemoryContext, ViewContext}, + key_value_store_view::{KeyValueStoreView, ViewContainer}, log_view::HashedLogView, - lru_caching::{LruCachingMemoryContext, LruCachingStore}, + lru_caching::{LruCachingMemoryStore, LruCachingStore}, map_view::{ByteMapView, HashedMapView}, - memory::{create_test_memory_context, create_test_memory_store, MemoryContext, MemoryStore}, + memory::{create_test_memory_store, MemoryStore}, queue_view::HashedQueueView, reentrant_collection_view::HashedReentrantCollectionView, register_view::HashedRegisterView, @@ -36,8 +36,7 @@ use linera_views::{ #[cfg(with_dynamodb)] use linera_views::{ dynamo_db::{ - create_dynamo_db_common_config, DynamoDbContext, DynamoDbStore, DynamoDbStoreConfig, - LocalStackTestContext, + create_dynamo_db_common_config, DynamoDbStore, DynamoDbStoreConfig, LocalStackTestContext, }, test_utils::generate_test_namespace, }; @@ -105,7 +104,7 @@ pub struct KeyValueStoreTestStorage { #[async_trait] impl StateStorage for KeyValueStoreTestStorage { - type Context = KeyValueStoreMemoryContext; + type Context = ViewContext>>; async fn new() -> Self { let context = create_test_memory_context(); @@ -132,7 +131,7 @@ pub struct LruMemoryStorage { #[async_trait] impl StateStorage for LruMemoryStorage { - type Context = LruCachingMemoryContext; + type Context = ViewContext; async fn new() -> Self { let store = create_test_memory_store(); @@ -162,7 +161,7 @@ pub struct RocksDbTestStorage { #[cfg(with_rocksdb)] #[async_trait] impl StateStorage for RocksDbTestStorage { - type Context = RocksDbContext; + type Context = ViewContext; async fn new() -> Self { let store = create_rocks_db_test_store().await; @@ -177,7 +176,7 @@ impl StateStorage for RocksDbTestStorage { self.accessed_chains.insert(id); let root_key = bcs::to_bytes(&id)?; let store = self.store.clone_with_root_key(&root_key)?; - let context = RocksDbContext::create(store, id).await?; + let context = ViewContext::create_root_context(store, id).await?; StateView::load(context).await } } @@ -191,7 +190,7 @@ pub struct ScyllaDbTestStorage { #[cfg(with_scylladb)] #[async_trait] impl StateStorage for ScyllaDbTestStorage { - type Context = ScyllaDbContext; + type Context = ViewContext; async fn new() -> Self { let store = create_scylla_db_test_store().await; @@ -206,7 +205,7 @@ impl StateStorage for ScyllaDbTestStorage { self.accessed_chains.insert(id); let root_key = bcs::to_bytes(&id)?; let store = self.store.clone_with_root_key(&root_key)?; - let context = ScyllaDbContext::create(store, id).await?; + let context = ViewContext::create_root_context(store, id).await?; StateView::load(context).await } } @@ -220,7 +219,7 @@ pub struct DynamoDbTestStorage { #[cfg(with_dynamodb)] #[async_trait] impl StateStorage for DynamoDbTestStorage { - type Context = DynamoDbContext; + type Context = ViewContext; async fn new() -> Self { let localstack = LocalStackTestContext::new().await.expect("localstack"); @@ -245,7 +244,7 @@ impl StateStorage for DynamoDbTestStorage { self.accessed_chains.insert(id); let root_key = bcs::to_bytes(&id)?; let store = self.store.clone_with_root_key(&root_key)?; - let context = DynamoDbContext::create(store, id).await?; + let context = ViewContext::create_root_context(store, id).await?; StateView::load(context).await } }