7
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 19 Nov 2024
7 points (100.0% liked)
Rust Programming
8836 readers
2 users here now
founded 6 years ago
MODERATORS
You can't create a subset of an enum directly, but splitting this up into multiple types works. You can have
FunctionAError
with errors that function can produce and a variant for your common errors, andFunctionBError
which is similar:The try operator (
?
) will automatically useFrom
impls to convert errors for you as well. If a function returns a result containingMyErrorCommon
in your function and you use?
on it, it gets converted to that function's error type for you.thiserror
generates theFrom
impl for you if you use#[from]
.