gsp-wasm-interface 21.0.1

Types and traits for interfacing between the host and the wasm runtime.
Documentation
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::HostState;
use wasmtime::{Memory, Table};

#[derive(Default)]
pub struct StoreData {
	/// This will only be set when we call into the runtime.
	pub host_state: Option<HostState>,
	/// This will be always set once the store is initialized.
	pub memory: Option<Memory>,
	/// This will be set only if the runtime actually contains a table.
	pub table: Option<Table>,
}

impl StoreData {
	/// Returns a mutable reference to the host state.
	pub fn host_state_mut(&mut self) -> Option<&mut HostState> {
		self.host_state.as_mut()
	}

	/// Returns the host memory.
	pub fn memory(&self) -> Memory {
		self.memory.expect("memory is always set; qed")
	}
}