ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.08k stars 377 forks source link

Adding rust-like result conatainer? #409

Closed skorokhod closed 2 years ago

skorokhod commented 2 years ago

Thanks for the Great Library! What do you think about adding some Rust-like 'result' container (https://doc.rust-lang.org/std/result/) which can hold one of two value types. It's very convenient to use for functions which should return value or error-code. Moreover it can be integrated with optional-type to extract the result

jwellbelove commented 2 years ago

Thanks, I'll take a look.

EvenTang commented 2 years ago

Good idea. Actually, AutoSAR Adaptive, which is a standard in automotive industry, adopts the same idea. Specification of Core Types for Adaptive Platform.pdf is a very good reference. Chapter 7.1 is the error handling philosophy, and 8.3 describes the specification of Result.

And, _AUTOSAR_EXPAdaptivePlatformInterfacesGuidelines.pdf Chapter 2.1 well explains detail/usage.

Hope my comment is helpful.

jwellbelove commented 2 years ago

It sounds like a specialisation of the functionality of an etl::variant.

jwellbelove commented 2 years ago

I've just looked at the ara::core::Result class file on Github and it is based on a variant.

skorokhod commented 2 years ago

will it allow to use like Result<void, Error> or Result<int, int>?

jwellbelove commented 2 years ago

Yes, it would.

jwellbelove commented 2 years ago

20.17.0 Added etl::result