Possibility of adopting Rust's Error Handling?

user1234 user1234 at 12.de
Fri Apr 1 21:40:41 UTC 2022


On Thursday, 31 March 2022 at 22:05:30 UTC, mee6 wrote:
> On Thursday, 31 March 2022 at 21:35:00 UTC, user1234 wrote:
>> On Thursday, 31 March 2022 at 21:21:04 UTC, mee6 wrote:
>>> Rust's error handling is pretty good, I think they've proved 
>>> the use of Result!(T, E). I was just always getting 
>>> informative messages from the get go. I think there's a @nogc 
>>> exception DIP in the works but I think this way of handling 
>>> errors is better.
>>>
>>> I won't go too much into detail of rust as this website does 
>>> a good job of going over it.
>>>
>>> https://doc.rust-lang.org/book/ch09-00-error-handling.html
>>>
>>> Anyways this could be adopted instead of trying to get @nogc 
>>> exceptions working. Rust uses exceptions but only for 
>>> panic!() Which terminates the application. All it does is 
>>> rewind the stack to see all the function calls for debugging 
>>> pretty much.
>>>
>>> I also think it works with chaining functions as that's what 
>>> Rust does a lot too. They have a `?` operator that does 
>>> basically this boiler plate code.
>>>
>>> ```d
>>> auto result = expr;
>>> if (result.isErr())
>>>     return result;
>>> ```
>>>
>>> D could implement this fairly easily and without much 
>>> intrusion, but it would add a lot of value to be able to do 
>>> something like:
>>>
>>> ```rust
>>> auto value = chain()?.funcs()?;
>>> ```
>>
>> yikes, I'd prefer if D could use `?` for [safe navigation].
>>
>>> While being @nogc and without using exceptions. Other than 
>>> for panics.
>>
>> [safe navigation]: 
>> https://en.wikipedia.org/wiki/Safe_navigation_operator
>
> That is Rust's equivalent.
>
> https://en.m.wikipedia.org/wiki/Safe_navigation_operator#Rust

yeah, nice. Everyone needs to see that and think twice.

Is Rust awefull afterall ?


More information about the Digitalmars-d mailing list