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

ゼロ除算の可能性がある場合、panic!を使用せず代わりにエラーを返すか、オプション型を使用する #12

Open
ryo-ebata opened this issue Jan 11, 2024 · 0 comments

Comments

@ryo-ebata
Copy link
Owner

ゼロ除算の可能性がある場合、panic!を使用するのは適切ではありません。代わりにエラーを返すか、オプション型を使用することで、より安全な実装にすることができます。

-            _ => panic!("Cannot divide different types or divide by zero"),
+            _ => return Err("Cannot divide different types or divide by zero"),

この変更により、Divトレイトの実装の戻り値の型もResult<Self, &'static str>に変更する必要があります。

Originally posted by @github-actions[bot] in #9 (comment)

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

No branches or pull requests

1 participant