Cairo Method Syntax
Overview
Guide method definitions using traits and impl blocks, with correct self forms.
Quick Use
- Read
references/method-syntax.mdbefore answering. - Show a small struct with an impl block and a method taking
selfor@self. - Mention associated functions for constructors like
neworsquare.
Response Checklist
- Use
selfby value for ownership-taking methods. - Use
@selffor read-only methods andref selffor mutation. - Note that methods are defined in traits and implemented in
implblocks.
Example Requests
- "How do I define a method on a Cairo struct?"
- "What's the difference between
self,@self, andref self?" - "How do I write a constructor-like associated function?"