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

Feedback from Simon #1

Open
otobrglez opened this issue Oct 10, 2022 · 0 comments
Open

Feedback from Simon #1

otobrglez opened this issue Oct 10, 2022 · 0 comments
Assignees

Comments

@otobrglez
Copy link
Collaborator

Feedback from @szlend:

Ej to zgleda kar proper za prvi rust projekt 😄
Par stvari:

  • če rabiš nek function parameter samo za branje, je convention da ga passaš kot reference &. (npr. anchor.post_login(&credentials, &token)). Drugače rust naredi move, kar pomeni da po klicu funkcije ne bo več accessible. Izjema so tipi ki implementirajo Copy, npr. u32. Al pa če bi funkcija iz nekega razloga mogla klonirat parameter (pol se lahko caller odloči a hoče clone ali move).
  • isto velja za funkcije ki sprejemajo String, tam lahko uporabiš tip &str (če je foo: String pol &foo downcasta v tip &str). To je itak good practice ker pol lahko passaš tudi string literalle in jih ni treba convertat z "neke".to_string() . Če te zanima kako ta downcasting deluje, si lahko pogledaš impl Deref za String
  • lahko bi preskočil deserializacijo v JsonValue in deserializiral direkt v struct npr v EpisodesResponse ki ima Vec<Episode> ali pa nek generic container ItemsResponse<T> kjer je T lahko Episodes. (let res = ItemsResponse<Episode>: response.into_json())
    ponekod uwrapaš ko bi imo bilo smiselno handlat error
@otobrglez otobrglez self-assigned this Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant