### Install Rustup Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Installs Rustup, the toolchain installer for Rust. This is the first step in setting up the Rust development environment. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Open Local Documentation with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Builds and opens the project's documentation locally using the Makefile. Useful for reviewing API docs and project guides. ```bash make doc ``` -------------------------------- ### Install Rust Stable Toolchain Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Installs the stable Rust toolchain and adds the wasm32v1-none target, which is necessary for building WebAssembly contracts. ```bash rustup install stable rustup +stable target add wasm32v1-none ``` -------------------------------- ### Rust Soroban Smart Contract Example Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/README.md A basic Rust smart contract for Soroban, demonstrating contract definition, implementation, and a test case. ```rust use soroban_sdk::{contract, contractimpl, vec, symbol_short, BytesN, Env, Symbol, Vec}; #[contract] pub struct Contract; #[contractimpl] impl Contract { pub fn hello(env: Env, to: Symbol) -> Vec { vec![&env, symbol_short!("Hello"), to] } } #[test] fn test() { # } # #[cfg(feature = "testutils")] # fn main() { let env = Env::default(); let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let words = client.hello(&symbol_short!("Dev")); assert_eq!(words, vec![&env, symbol_short!("Hello"), symbol_short!("Dev"),]); } # #[cfg(not(feature = "testutils"))] # fn main() { } ``` -------------------------------- ### Install Cargo Tools Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Installs the cargo-hack tool, which is used for managing Cargo features and dependencies, ensuring reproducible builds. ```bash cargo install --locked cargo-hack ``` -------------------------------- ### Install Rust Nightly Toolchain Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Installs the nightly Rust toolchain and adds the wasm32v1-none target. Nightly is often required for experimental features or specific development tools like MIRI. ```bash rustup install nightly rustup +nightly target add wasm32v1-none ``` -------------------------------- ### Trait Definition with Default Functions Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/docs/contracttrait.md Example of a trait definition including functions with and without default implementations, as processed by the `#[contracttrait]` macro. ```Rust trait Pause { // fn without impl fn f1(...); // fn with default impl fn f2(...) { ... } } ``` -------------------------------- ### Contract Trait Implementation with #[contractimpl] Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/docs/contracttrait.md Example of implementing a trait within a contract using the `#[contractimpl(contracttrait)]` attribute. This enables the macro to process trait defaults. ```rust #[contractimpl(contracttrait)] impl Pause for Contract { fn f1() { ... } } ``` -------------------------------- ### Build Project with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Executes the build command defined in the Makefile. Compiles the project's crates and generates artifacts. ```bash make build ``` -------------------------------- ### Run Tests with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Executes all project tests using the Makefile. This is a standard command for verifying code correctness. ```bash make test ``` -------------------------------- ### Format Code with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Runs the code formatting command using the project's Makefile. Ensures code adheres to project style guidelines. ```bash make fmt ``` -------------------------------- ### Print Minimum Supported Rust Version (MSRV) with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Prints the minimum supported Rust version for the project, as defined in the Makefile. Important for maintaining compatibility. ```bash make msrv ``` -------------------------------- ### Build Fuzz Tests with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Builds fuzz tests for the project, requiring a nightly Rust toolchain. This command is used for security and robustness testing. ```bash make build-fuzz ``` -------------------------------- ### Clean Build Artifacts with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Removes generated build artifacts and intermediate files using the Makefile. Useful for ensuring a clean build environment. ```bash make clean ``` -------------------------------- ### Run MIRI for Memory Safety with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Runs tests using MIRI, a memory safety checker for Rust, requiring a nightly toolchain. This command helps detect memory-related bugs. ```bash make miri ``` -------------------------------- ### Expand Test Macros with Make Source: https://github.com/stellar/rs-soroban-sdk/blob/main/CONTRIBUTING.md Expands macro-generated code in test contracts, as defined in the Makefile. Useful for reviewing changes in code generation and debugging macro issues. ```bash make expand-tests ``` -------------------------------- ### Generated Helper Attributes for `#[contracttrait]` Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/docs/contracttrait.md When `#[contracttrait]` is applied to a trait, it generates four additional attributes to process the trait definition. ```Rust #[contractspecfn(name = "PauseSpec", export = false)] #[contractargs(name = "PauseArgs")] #[contractclient(crate_path = soroban_sdk, name = "PauseClient")] #[contractimpl_trait_macro(crate_path = soroban_sdk)] trait Pause { ... } ``` -------------------------------- ### Generated Trait Macro Call Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/docs/contracttrait.md The `contractimpl` macro generates a call to the trait's specific macro (e.g., `Pause!`) with the list of implemented functions. This is part of the process for handling trait defaults. ```rust Pause!( Contract, ["f1"], //... ); ``` -------------------------------- ### Declarative Macro Generated by `#[contractimpl_trait_macro]` Source: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/docs/contracttrait.md This attribute generates a declarative macro named after the trait (e.g., `Pause!`) to handle default trait functions. ```Rust #[doc(hidden)] #[macro_export] macro_rules! __contractimpl_for_pause { (/* ... */, $impl_fns:expr, /* ... */) => { soroban_sdk::contractimpl_trait_default_fns_not_overridden!( trait_default_fns = ["#[doc(...)] fn f2(_)"], impl_fns = $impl_fns, //... ); } } pub use __contractimpl_for_pause as Pause; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.