Methods on structs
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 48/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- rust
- Ambito
- documentation
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 3.9k
- Fork
- 297
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nrc/r4cppp
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
make_unique call typoAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
Problem with "primitives.md"Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 42/100
Issue simili
-
llm translation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
area: backend type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
armadavalor/WinKnife#6 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
5omeOtherGuy/phaseone#870 ·
I maintainer di solito rispondono entro 1 giorno
-
Write a support policyAperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
MattA-Official/vwmcp#20 ·