Standard Library

The Move Standard Library provides functionality for native types and operations. It is a standard collection of modules which do not interact with the storage, but provide basic tools for working and manipulating the data. It is the only dependency of the Sui Framework, and is imported together with it.

Most Common Modules

In this book we go into detail about most of the modules in the Standard Library, however, it is also helpful to give an overview of the features, so that you can get a sense of what is available and which module implements it.

ModuleDescriptionChapter
std::stringProvides basic string operationsString
std::asciiProvides basic ASCII operationsString
std::optionImplements an Option<T>Option
std::vectorNative operations on the vector typeVector
std::bcsContains the bcs::to_bytes() functionBCS
std::addressContains a single address::length functionAddress
std::type_nameAllows runtime type reflectionType Reflection
std::hashHashing functions: sha2_256 and sha3_256Cryptography and Hashing
std::debugContains debugging functions, which are available in only in test modeDebugging
std::bit_vectorProvides operations on bit vectors-
std::fixed_point32Provides the FixedPoint32 type-

Integer Modules

The Move Standard Library provides a set of functions associated with integer types. These functions are split into multiple modules, each associated with a specific integer type. The modules should not be imported directly, but their functions are available on every integer value.

All of the modules provide the same set of functions. Namely, max, diff, divide_and_round_up, sqrt and pow.

ModuleDescription
std::u8Functions for the u8 type
std::u16Functions for the u16 type
std::u32Functions for the u32 type
std::u64Functions for the u64 type
std::u128Functions for the u128 type
std::u256Functions for the u256 type

Exported Addresses

Standard Library exports one named address - std = 0x1.

[addresses]
std = "0x1"

Implicit Imports

Some of the modules are imported implicitly, and are available in the module without explicit use import. For Standard Library, these modules and types are:

  • std::vector
  • std::option
  • std::option::Option

Importing std without Sui Framework

The Move Standard Library can be imported to the package directly. However, std alone is not enough to build a meaningful application, as it does not provide any storage capabilities, and can't interact with the on-chain state.

MoveStdlib = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "framework/mainnet" }

Source Code

The source code of the Move Standard Library is available in the Sui repository.