Skip to main content
The StateAdapter trait defines the interface for state persistence in III. State adapters allow you to store, retrieve, and manipulate key-value data across different storage backends.

Trait Definition

Source: /workspace/source/src/modules/state/adapters/mod.rs:16

Methods

set

Stores a value in the state store. Parameters:
  • scope - The namespace or group for the key
  • key - The unique identifier within the scope
  • value - JSON value to store
Returns: SetResult containing information about the operation

get

Retrieves a value from the state store. Parameters:
  • scope - The namespace or group for the key
  • key - The unique identifier within the scope
Returns: Some(Value) if found, None if not found

delete

Removes a key-value pair from the state store. Parameters:
  • scope - The namespace or group for the key
  • key - The unique identifier within the scope

update

Performs atomic update operations on a stored value. Parameters:
  • scope - The namespace or group for the key
  • key - The unique identifier within the scope
  • ops - Vector of update operations to apply
Returns: UpdateResult containing the updated value

list

Lists all values within a scope. Parameters:
  • scope - The namespace or group to list
Returns: Vector of all values in the scope

list_groups

Lists all available scopes/groups in the state store. Returns: Vector of scope names

destroy

Cleans up resources and closes connections for the adapter.

UpdateOp

The UpdateOp enum defines atomic operations that can be applied to stored values:

Update Operations

  • Set: Sets a field at the specified path to a new value
  • Merge: Merges an object with the existing value
  • Increment: Adds a numeric value to a field
  • Decrement: Subtracts a numeric value from a field
  • Remove: Removes a field at the specified path

Available Adapters

RedisAdapter

Redis-based state persistence with atomic operations.
Source: /workspace/source/src/modules/state/adapters/redis_adapter.rs

KvStore

In-memory key-value store for development and testing.
Source: /workspace/source/src/modules/state/adapters/kv_store.rs

Bridge

Bridges state operations to another III instance.
Source: /workspace/source/src/modules/state/adapters/bridge.rs

Example Implementation