Skip to content

docs: add Rust doc comments to hello_world, timelock, and events examples - #402

Open
turanalmammadov wants to merge 1 commit into
stellar:mainfrom
turanalmammadov:docs/add-rust-doc-comments-to-examples
Open

docs: add Rust doc comments to hello_world, timelock, and events examples#402
turanalmammadov wants to merge 1 commit into
stellar:mainfrom
turanalmammadov:docs/add-rust-doc-comments-to-examples

Conversation

@turanalmammadov

Copy link
Copy Markdown

Summary

Adds Rust doc comments (///) to public types, functions, and enum variants in three core examples, following the Google style guide for docstrings as suggested in #280.

Examples updated

hello_world

  • Contract struct doc comment
  • hello() function: Args and Returns sections

timelock

  • DataKey enum variant docs
  • TimeBoundKind enum and variant docs
  • TimeBound struct and field docs
  • ClaimableBalance struct and field docs
  • ClaimableBalanceContract struct doc
  • deposit(): Args and Panics sections
  • claim(): Args and Panics sections

events

  • IncrementContract struct doc
  • increment(): Args and Returns sections

Why this matters

Rust doc comments in Soroban contracts appear in:

  1. Generated TypeScript bindings — enabling better autocomplete and hover docs in frontend IDEs
  2. soroban-cli help output — operators see these when inspecting deployed contracts

Closes #280 (partial — more examples can be covered in follow-up PRs)

Made with Cursor

…ples

Adds doc comments to public types, functions, and enums following
Google style guide as suggested in issue stellar#280.

- hello_world: Contract struct doc comment; hello() function docs with
  Args and Returns sections
- timelock: DataKey enum variant docs; TimeBoundKind enum and variant
  docs; TimeBound struct and field docs; ClaimableBalance struct and
  field docs; ClaimableBalanceContract struct doc; deposit() docs with
  Args and Panics sections; claim() docs with Args and Panics sections
- events: IncrementContract struct doc; increment() docs with Args and
  Returns sections

Doc comments in Soroban contracts appear in generated TypeScript
bindings and soroban-cli help output, improving the developer
experience for users of these example contracts.

Part of stellar#280

Made-with: Cursor
Copilot AI review requested due to automatic review settings March 3, 2026 21:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Rust doc comments to Soroban example contracts so generated bindings and CLI help have richer documentation, aligning with the goal in #280.

Changes:

  • Added /// docs for core public types and storage keys in timelock.
  • Added function docs (Args/Returns/Panics) for key public contract methods (hello, deposit, claim, increment).
  • Updated the events example to document the increment behavior and emitted event.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
timelock/src/lib.rs Adds docs for storage keys, time-bound types, and deposit/claim methods.
hello_world/src/lib.rs Adds docs for the contract and hello() method (args/returns).
events/src/lib.rs Adds docs for the contract and increment() method (args/returns + event description).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread timelock/src/lib.rs
Comment on lines +20 to +26
/// Defines whether the timelock expires before or after a given timestamp.
#[derive(Clone)]
#[contracttype]
pub enum TimeBoundKind {
/// The claim is only valid before the specified timestamp.
Before,
/// The claim is only valid after the specified timestamp.

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeBoundKind docs say the claim is valid "before" / "after" the timestamp, but check_time_bound uses <= for Before and >= for After (inclusive). Please adjust the variant doc comments to reflect the inclusive semantics (e.g., "at or before" / "at or after") so generated bindings/CLI help are accurate.

Suggested change
/// Defines whether the timelock expires before or after a given timestamp.
#[derive(Clone)]
#[contracttype]
pub enum TimeBoundKind {
/// The claim is only valid before the specified timestamp.
Before,
/// The claim is only valid after the specified timestamp.
/// Defines whether the timelock expires at or before, or at or after, a given timestamp.
#[derive(Clone)]
#[contracttype]
pub enum TimeBoundKind {
/// The claim is only valid at or before the specified timestamp.
Before,
/// The claim is only valid at or after the specified timestamp.

Copilot uses AI. Check for mistakes.
Comment thread events/src/lib.rs
#[contractimpl]
impl IncrementContract {
/// Increment increments an internal counter, and returns the value.
/// Increments an internal counter and emits a `COUNTER/increment` event.

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment says this emits a COUNTER/increment event, but the event is defined as two static topics: "COUNTER" and "increment" via #[contractevent(topics = ...)]. To avoid confusion in generated docs, consider describing the event in terms of its topics (and data payload) rather than a single combined name, unless COUNTER/increment is a guaranteed/standard rendering in your tooling.

Suggested change
/// Increments an internal counter and emits a `COUNTER/increment` event.
/// Increments an internal counter and emits a Soroban event with topics
/// `"COUNTER"` and `"increment"`, using the new counter value as the
/// single-value data payload.

Copilot uses AI. Check for mistakes.
@leocagli

Copy link
Copy Markdown

Hi, I'd like to add Rust doc comments to the hello_world, timelock, and events contract examples. I'm familiar with Soroban SDK patterns. Could you assign me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add rust doc comments to all types and functions in all examples

3 participants