refactor: use free functions instead of impl methods in Anchor examples#561
Open
mikemaccana-edwardbot wants to merge 12 commits intosolana-developers:mainfrom
Open
refactor: use free functions instead of impl methods in Anchor examples#561mikemaccana-edwardbot wants to merge 12 commits intosolana-developers:mainfrom
mikemaccana-edwardbot wants to merge 12 commits intosolana-developers:mainfrom
Conversation
- Update anchor-lang and anchor-spl to 1.0.0 in all Cargo.toml files - Update @anchor-lang/core to 1.0.0 in all package.json files - Remove stale RC pin comments from Cargo.toml files - Update .reference/ANCHOR-1.0-MIGRATION.md to reflect stable release - Keep all existing tests unchanged (no LiteSVM additions)
…amples Converts all Anchor examples from impl blocks on account constraint structs to free handler functions. Structs renamed to *AccountConstraints, variable name ctx → context, self.field → accounts.field throughout. This removes fake OOP — the methods never modified instance state, they just needed access to accounts. Free functions make this explicit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #558 (Anchor 1.0 stable).
Refactors all Anchor examples to use free handler functions instead of impl blocks on account constraint structs.
Why
The impl pattern is fake OOP — the methods don't modify instance state, they just need access to accounts. Free functions make this explicit and are more consistent with Rust conventions.
Changes
AccountConstraintsctx→contextthroughoutself.field→accounts.fieldin handler functionscontext.accounts.method()→instructions::handle_method(&mut context.accounts)in lib.rs