Skip to content

Commit eef9cdb

Browse files
committed
Tidy up ModuleKind conversions a tiny bit
1 parent 380acf1 commit eef9cdb

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

crates/core/src/db/datastore/system_tables.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,18 @@ impl From<StRowLevelSecurityRow> for RowLevelSecuritySchema {
813813
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
814814
pub struct ModuleKind(u8);
815815

816-
/// The [`ModuleKind`] of WASM-based modules.
817-
///
818-
/// This is currently the only known kind.
819-
pub const WASM_MODULE: ModuleKind = ModuleKind(0);
816+
impl ModuleKind {
817+
/// The [`ModuleKind`] of WASM-based modules.
818+
pub const WASM: ModuleKind = ModuleKind(0);
819+
}
820+
821+
impl From<crate::messages::control_db::HostType> for ModuleKind {
822+
fn from(host_type: crate::messages::control_db::HostType) -> Self {
823+
match host_type {
824+
crate::messages::control_db::HostType::Wasm => Self::WASM,
825+
}
826+
}
827+
}
820828

821829
impl_serialize!([] ModuleKind, (self, ser) => self.0.serialize(ser));
822830
impl_deserialize!([] ModuleKind, de => u8::deserialize(de).map(Self));
@@ -852,7 +860,7 @@ impl From<Identity> for IdentityViaU256 {
852860
///
853861
/// * `database_identity` is the [`Identity`] of the database.
854862
/// * `owner_identity` is the [`Identity`] of the owner of the database.
855-
/// * `program_kind` is the [`ModuleKind`] (currently always [`WASM_MODULE`]).
863+
/// * `program_kind` is the [`ModuleKind`] (currently always [`ModuleKind::WASM`]).
856864
/// * `program_hash` is the [`Hash`] of the raw bytes of the (compiled) module.
857865
/// * `program_bytes` are the raw bytes of the (compiled) module.
858866
/// * `module_version` is the version of the module.

crates/core/src/db/relational_db.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::datastore::{
1717
traits::TxData,
1818
};
1919
use super::db_metrics::DB_METRICS;
20-
use crate::db::datastore::system_tables::{StModuleRow, WASM_MODULE};
20+
use crate::db::datastore::system_tables::StModuleRow;
2121
use crate::error::{DBError, DatabaseError, RestoreSnapshotError};
2222
use crate::execution_context::{ReducerContext, Workload, WorkloadType};
2323
use crate::messages::control_db::HostType;
@@ -427,9 +427,7 @@ impl RelationalDB {
427427
database_identity: self.database_identity.into(),
428428
owner_identity: self.owner_identity.into(),
429429

430-
program_kind: match host_type {
431-
HostType::Wasm => WASM_MODULE,
432-
},
430+
program_kind: host_type.into(),
433431
program_hash: program.hash,
434432
program_bytes: program.bytes,
435433
module_version: ONLY_MODULE_VERSION.into(),
@@ -473,10 +471,7 @@ impl RelationalDB {
473471
/// - the `__init__` reducer contained in the module has been executed
474472
/// within the transactional context `tx`.
475473
pub fn update_program(&self, tx: &mut MutTx, host_type: HostType, program: Program) -> Result<(), DBError> {
476-
let program_kind = match host_type {
477-
HostType::Wasm => WASM_MODULE,
478-
};
479-
Ok(self.inner.update_program(tx, program_kind, program)?)
474+
Ok(self.inner.update_program(tx, host_type.into(), program)?)
480475
}
481476

482477
fn restore_from_snapshot_or_bootstrap(

0 commit comments

Comments
 (0)