Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc comments about why symbol_short! #1064

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion soroban-sdk/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,30 @@ impl Symbol {
///
/// Valid characters are `a-zA-Z0-9_` and maximum length is 9 characters.
///
/// The conversion can happen at compile time.
/// The conversion can happen at compile time if called in a const context,
/// such as:
///
/// ```rust
/// # use soroban_sdk::Symbol;
/// const SYMBOL: Symbol = Symbol::short("abcde");
/// ```
///
/// Note that when called from a non-const context the conversion will occur
/// at runtime and the conversion logic will add considerable number of
/// bytes to built wasm file. For this reason the function should be generally
/// avoided:
///
/// ```rust
/// # use soroban_sdk::Symbol;
/// let SYMBOL: Symbol = Symbol::short("abcde"); // AVOID!
/// ```
///
/// Instead use the `symbol_short!()` macro that will ensure the conversion always occurs in a const-context:
///
/// ```rust
/// # use soroban_sdk::{symbol_short, Symbol};
/// let SYMBOL: Symbol = symbol_short!("abcde"); // 👍
/// ```
///
/// ### Panics
///
Expand Down