Skip to content

Commit

Permalink
codig-convention: update sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
zakuro9715 committed Oct 2, 2023
1 parent c668cc5 commit 7ae8306
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions docs/coding-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,34 @@ fn (m PartialMessage) full_text() !string {

```
// Message represents a message.
[noinit]
struct Message {
pub:
sender string
text string
}
// Message.new creates `Message` from `sender` and `text`.
fn Message.new(sender string, text string) Message {
// MessageParams is the parameters for `Message.new`.
struct Message {
pub:
sender string
text string
}
// Message.new creates `Message`.
fn Message.new(p MessageParams) Message {
return Message {
sender: sender
text: text
sender: p.sender
text: p.text
}
}
// full_text returns formatted text.
// Message.from_text creates `Message` from `text`.
fn Message.from_text(text: string) Message {
return Message.new(sender: '', text: text)
}
// full_text returns the full text.
fn (m Message) full_text() string {
return '${m.sender}: ${m.text}'
}
Expand Down

0 comments on commit 7ae8306

Please sign in to comment.