Methods on structs
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- documentation
Research direction
Search the documentation for the quoted data types text and read the surrounding discussion of traits and impls. Update the explanation to distinguish methods from functions and include the provided struct example; done means the section no longer implies structs cannot have methods.
Written by the indexing model from the issue text.
Description
In the section on data types it states:
A rust struct is similar to a C struct or a C++ struct without methods. Simply a list of named fields. The syntax is best seen with an example:
This statement is misleading because it suggests that methods can not be defined for a struct, while methods can be defined via impl blocks. There is a brief mention of this possibility with:
Behaviour is defined by functions and those can be defined in traits and impls
However, this suggests the impls would define functions rather than methods, while in fact impls can define both.
For reference here is a short example outlining the type of functionality I am describing.
struct Example {
foo: i16,
bar: i16,
}
impl Example {
fn baz(&self) -> i16 {
self.foo + self.bar
}
}
fn main() {
let ex = Example {
foo: 3,
bar: -1,
};
println!("{}", ex.baz());
}
This will print 2. I believe a section on this functionality should be added as it is critical to creating useful abstractions.
- Dominant language
- Rust
- Stars
- 3.9k
- Forks
- 297
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nrc/r4cppp
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
Similar issues
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
n0-computer/iroh#4550 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
paritytech/zombienet-sdk#591 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
farion1231/cc-switch#7638 · 1 comment ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100