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

Add convenience trait impls for CName #40

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

Roms1383
Copy link
Contributor

2 simple traits impl for CName :

  • AsRef<str>
  • ToString

Concerning safety, I assumed from resolve_cname signature that AsRef<str> is safe since it returns a &'static str, but let me know if there's any concern with it. Otherwise having simply ToString will already improve ergonomics a bit :)

@jac3km4
Copy link
Owner

jac3km4 commented Dec 14, 2023

I wouldn't implement AsRef<str> here because it's meant to be used for simple reference to reference conversions and this involves doing a lookup in a pool managed by the game.
As for ToString, I think it's okay, although it's probably a better idea to implement fmt::Display, since ToString is automatically implemented for types with fmt::Display

@Roms1383
Copy link
Contributor Author

@jac3km4 I also added #[cfg(not(test))], to prevent people from inadvertently using Display in their unit-tests, since resolve_cname can only be used in-game. Let me know if there's a better directive.

@jac3km4 jac3km4 merged commit 52ee3f3 into jac3km4:master Dec 15, 2023
4 checks passed
@Roms1383 Roms1383 deleted the feat/cname-tostring branch December 15, 2023 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants