amazon-ion / ion-schema-rust

Rust implementation of Ion Schema
https://amazon-ion.github.io/ion-schema/sandbox
Apache License 2.0
12 stars 6 forks source link

Clean up IonSchemaError and IonSchemaResult constructor functions #196

Open popematt opened 1 year ago

popematt commented 1 year ago

ion-schema-rust should implement a similar approach as what is described here:

🗺️ IonFailure (imported above on line 5) is a new crate-visible trait that provides extension methods for the IonResult and IonError types.

Previously, each IonError variant had one helper function in crate::result that would build an IonResult, and an accompanying function that would being an IonError. The names got pretty weird. For example, decoding_error would return an IonResult (not an error, as one could reasonably infer), and decoding_error_raw would return an IonError. (The "raw" indicated that it hadn't gone through the final step of wrapping the IonError in a Result::Err, which was not an obvious connection.)

The IonFailure trait replaces those method pairs. Now you can use IonResult::decoding_error to make an IonResult and you can use IonError::decoding_error to make an IonError. Much more straightforward.

_Originally posted by @zslayton in https://github.com/amazon-ion/ion-rust/pull/584#discussion_r1251096891_