Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[idioms/ctor] adds default constructor section #280

Merged
Prev Previous commit
Next Next commit
[ctor] adds fn value for examples to work
  • Loading branch information
wookietreiber committed Nov 21, 2021
commit c0f1670fe1cd8490034856f0bedc828fc36162ca
19 changes: 19 additions & 0 deletions idioms/ctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ impl Second {
pub fn new(value: u64) -> Self {
simonsan marked this conversation as resolved.
Show resolved Hide resolved
Self { value }
}

/// Returns the value in seconds.
pub fn value(&self) -> u64 {
self.value
}
}
```

Expand All @@ -44,6 +49,13 @@ pub struct Second {
value: u64
}

impl Second {
/// Returns the value in seconds.
pub fn value(&self) -> u64 {
self.value
}
}

impl Default for Second {
fn default() -> Self {
Self { value: 0 }
Expand All @@ -67,6 +79,13 @@ like they do with `Second`:
pub struct Second {
value: u64
}

impl Second {
/// Returns the value in seconds.
pub fn value(&self) -> u64 {
self.value
}
}
```

**Note:** When implementing `Default` for a type, it is neither required nor
Expand Down