docs: add Rust doc comments to hello_world, timelock, and events examples - #402
Conversation
…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
There was a problem hiding this comment.
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 intimelock. - Added function docs (Args/Returns/Panics) for key public contract methods (
hello,deposit,claim,increment). - Updated the
eventsexample 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.
| /// 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. |
There was a problem hiding this comment.
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.
| /// 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. |
| #[contractimpl] | ||
| impl IncrementContract { | ||
| /// Increment increments an internal counter, and returns the value. | ||
| /// Increments an internal counter and emits a `COUNTER/increment` event. |
There was a problem hiding this comment.
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.
| /// 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. |
|
Hi, I'd like to add Rust doc comments to the |
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_worldhello()function: Args and Returns sectionstimelockDataKeyenum variant docsTimeBoundKindenum and variant docsTimeBoundstruct and field docsClaimableBalancestruct and field docsClaimableBalanceContractstruct docdeposit(): Args and Panics sectionsclaim(): Args and Panics sectionseventsIncrementContractstruct docincrement(): Args and Returns sectionsWhy this matters
Rust doc comments in Soroban contracts appear in:
Closes #280 (partial — more examples can be covered in follow-up PRs)
Made with Cursor