Ubospica commented on PR #399: URL: https://github.com/apache/tvm-ffi/pull/399#issuecomment-3822626031
Thanks for the thorough discussion! I agree it would be great to follow C++ conventions. Adding implicit conversion looks like a reasonable approach. I also checked XGrammar's implementation of Expected (at https://github.com/Ubospica/xgrammar/blob/15dc61d02ed24820215ca1d491d6a07ba32fff50/cpp/support/utils.h#L251, called Result). It's more like a C++ imitation of the Result in rust. There is one difference in usage: It allows enum-based error. ``` enum class SchemaErrorType : int { kInvalidSchema = 0, kUnsatisfiableSchema = 1, }; using SchemaError = TypedError<SchemaErrorType>; Result<SchemaSpecPtr, SchemaError> Parse( const picojson::value& schema, const std::string& rule_name_hint = "root" ); ``` `std::expected` also supports it through customizing E to an enum class in `std::expected<T, E>`. We currently restrict the error kind to `tvm::ffi::Error`. I think the design is good because it simplifies the error handling. Also, it allows customizing the kind through its `std::string kind` parameter. In comparison, the enum-based error would be more efficient, but I don't think it's a blocker. To support this, we may consider supporting errno in the Error class in the future. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
