Skip to content

Commit

Permalink
refactor: replace strum with name_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Mar 12, 2022
1 parent c623e0a commit 43a40d9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sui_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ move-core-types = { git = "https://github.com/diem/move", rev = "584bfc8c5f8e582
move-package = { git = "https://github.com/diem/move", rev = "584bfc8c5f8e582223581975106ffa2545677e2a" }
move-vm-runtime = { git = "https://github.com/diem/move", rev = "584bfc8c5f8e582223581975106ffa2545677e2a" }

typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "a36c852c30729a16ee3c8a6a863f654887f0c30e"}
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "97a056f85555fa2afe497d6abb7cf6bf8faa63cf"}

[dev-dependencies]
fdlimit = "0.2.1"
Expand Down
5 changes: 2 additions & 3 deletions sui_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ serde_json = "1.0.79"
serde_with = "1.12.0"
signature = "1.5.0"
static_assertions = "1.1.0"
strum = "0.24.0"
strum_macros = "0.24.0"

typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev ="a36c852c30729a16ee3c8a6a863f654887f0c30e"}
name_variant = { git = "https://github.com/MystenLabs/mysten-infra", rev ="97a056f85555fa2afe497d6abb7cf6bf8faa63cf"}
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev ="97a056f85555fa2afe497d6abb7cf6bf8faa63cf"}

move-binary-format = { git = "https://github.com/diem/move", rev = "584bfc8c5f8e582223581975106ffa2545677e2a" }
move-bytecode-utils = { git = "https://github.com/diem/move", rev = "584bfc8c5f8e582223581975106ffa2545677e2a" }
Expand Down
17 changes: 3 additions & 14 deletions sui_types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod messages_tests;

use move_binary_format::{access::ModuleAccess, CompiledModule};
use move_core_types::{identifier::Identifier, language_storage::TypeTag, value::MoveStructLayout};
use name_variant::NamedVariant;
use serde::{Deserialize, Serialize};
use static_assertions::const_assert_eq;
use std::fmt::Write;
Expand All @@ -22,7 +23,6 @@ use std::{
collections::{BTreeSet, HashSet},
hash::{Hash, Hasher},
};
use strum::VariantNames;

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub struct Transfer {
Expand Down Expand Up @@ -53,9 +53,7 @@ pub struct MoveModulePublish {
pub gas_budget: u64,
}

#[derive(
Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, strum_macros::EnumVariantNames,
)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, NamedVariant)]
pub enum TransactionKind {
/// Initiate an object transfer between addresses
Transfer(Transfer),
Expand Down Expand Up @@ -135,16 +133,7 @@ impl TransactionData {

/// Returns the transaction kind as a &str (variant name, no fields)
pub fn kind_as_str(&self) -> &'static str {
// NOTE: Ideally we could have used something like https://docs.rs/strum/latest/strum/derive.AsRefStr.html
// The problem is that it doesn't actually return &'static ref due to &self above
// and we really want 'static for common situations, such as authority_server dispatch where
// by the time we instrument the transaction kind, the message or Transaction might have been moved
// and so the lifetime and Kind is out of scope and we cannot borrow it.
match self.kind {
TransactionKind::Transfer(_) => TransactionKind::VARIANTS[0],
TransactionKind::Publish(_) => TransactionKind::VARIANTS[1],
TransactionKind::Call(_) => TransactionKind::VARIANTS[2],
}
self.kind.variant_name()
}
}

Expand Down

0 comments on commit 43a40d9

Please sign in to comment.