Expand description
§talus-sui-move
Rust representations of Move types, built on top of sui-sdk-types.
This crate solves one problem: represent Move types precisely in Rust (including their
TypeTag/StructTag and ability surface), so you can build strongly typed Sui clients and
helpers that can verify type tags and decode BCS safely.
§How to use it
talus-sui-move provides shared type traits used by the other Talus Sui Move crates. It can also
be used independently to:
- name types precisely when building Move calls (
TypeTag/StructTag), - express Move ability constraints as normal Rust bounds,
- verify type tags returned from chain state and decode BCS in a controlled way.
§Quickstart
The core traits are MoveType and MoveStruct.
use talus_sui_move::prelude::*;
assert_eq!(<u64 as MoveType>::type_tag_static(), TypeTag::U64);
assert_eq!(
<Vec<u8> as MoveType>::type_tag_static(),
TypeTag::Vector(Box::new(TypeTag::U8)),
);§Core concepts
§MoveType and MoveStruct
MoveType means a Rust type knows how to describe itself as a Move TypeTag.
MoveStruct is the specialization for struct types that produces a StructTag.
For a Move struct type, you typically implement both:
use serde::{Deserialize, Serialize};
use talus_sui_move::{parse_address, parse_identifier, HasStore, MoveStruct, MoveType};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct MyCounter {
pub value: u64,
}
impl MoveType for MyCounter {
fn type_tag_static() -> sui_sdk_types::TypeTag {
sui_sdk_types::TypeTag::Struct(Box::new(Self::struct_tag_static()))
}
}
impl MoveStruct for MyCounter {
fn struct_tag_static() -> sui_sdk_types::StructTag {
sui_sdk_types::StructTag::new(
parse_address("0x123").expect("address literal"),
parse_identifier("counter").expect("module"),
parse_identifier("MyCounter").expect("name"),
vec![],
)
}
}
impl HasStore for MyCounter {}§Macros (feature derive)
If you prefer, enable the derive feature to use attribute macros for defining Rust structs that
represent Move structs.
#[cfg(feature = "derive")]
mod example {
use talus_sui_move::{move_struct, prelude::Address};
#[move_struct(address = "0x2", module = "object", abilities = "copy, drop, store")]
pub struct ID {
pub bytes: Address,
}
#[move_struct(address = "0x2", module = "object", abilities = "store")]
pub struct UID {
pub id: ID,
}
#[move_struct(address = "0x1", module = "vault", abilities = "key, store")]
pub struct Vault {
pub id: UID,
pub value: u64,
}
}§Move abilities as Rust bounds
Move abilities are modeled as marker traits (HasKey, HasStore, HasCopy, HasDrop), plus
small “ability surface” aliases:
Storable = MoveType + HasStoreCopyable = MoveType + HasCopy + HasDrop + CloneDroppable = MoveType + HasDrop
This lets you express the same constraints that Move does:
use talus_sui_move::Storable;
fn requires_store<T: Storable>(_: &T) {}
let x = 42u64;
requires_store(&x);§Decoding with tag verification (MoveInstance)
When you have (TypeTag, bytes) from the chain, you can decode and verify the tag matches the
Rust type you expect:
use talus_sui_move::{MoveInstance, MoveType};
let value = vec![1u8, 2, 3];
let bytes = value.to_bcs().unwrap();
let inst = MoveInstance::<Vec<u8>>::from_raw_type(
<Vec<u8> as MoveType>::type_tag_static(),
&bytes,
)
.unwrap();
assert_eq!(inst.value, vec![1u8, 2, 3]);§What’s included
§Standard Rust types
The crate implements MoveType (and ability markers) for:
u8,u16,u32,u64,u128,boolsui_sdk_types::AddressVec<T>whereT: MoveType
§Framework types are not core
talus-sui-move intentionally does not export handwritten mirrors for Sui framework packages such as
0x2::object::UID, 0x2::coin::Coin<T>, 0x2::balance::Balance<T>, or 0x1::option::Option<T>.
Those are datatypes defined by a package, not language atoms.
If application code needs framework types, generate them from package metadata or define them in
the consuming crate using the same MoveType / MoveStruct machinery used for user packages. This
keeps this crate focused and lets generated bindings represent each package exactly.
§What is deliberately excluded
- Framework mirrors such as
UID,ID,Coin<T>,Balance<T>,Table<K, V>, andClock - Package/module/function declaration IR
- Move expression/function body IR
- Transaction building or execution
§Module guide
talus_sui_move::prelude: convenient imports for common traits/typestalus_sui_move::decode: decoding helpers constrained by Move abilities
Re-exports§
pub use decode::decode_copyable;pub use decode::decode_keyed;pub use decode::decode_storable;
Modules§
- decode
- Decoding helpers constrained by Move abilities.
- prelude
- Convenient imports for working with this crate.
Structs§
- Move
Instance - A value paired with the Move type tag it was accompanied by.
- U256
- Move
u256value backed byethnum::U256.
Enums§
- Decode
Error - Errors that can occur when verifying or decoding Move data.
Traits§
- Copyable
- A convenient bound for types that have
copyanddrop. - Droppable
- A convenient bound for types that have the
dropability. - HasCopy
- Marker trait for the Move
copyability. - HasDrop
- Marker trait for the Move
dropability. - HasKey
- Marker trait for the Move
keyability. - HasStore
- Marker trait for the Move
storeability. - Move
Struct - A Move struct type (including any type parameters).
- Move
Type - A Rust type that corresponds to a Move type.
- Storable
- A convenient bound for types that have the
storeability.
Functions§
- parse_
address - Parse a Sui address (e.g.
"0x2"). - parse_
identifier - Parse a Move identifier (e.g. module or struct name).
- type_
tag_ of - Convenience helper to get a static
TypeTagfor anyMoveType.
Attribute Macros§
- move_
module - Marker attribute for Move module namespaces.
- move_
struct - Define a Rust struct that represents a Move struct and derive
talus-sui-movetraits.