refactor(sdk): convert bind-macro error/level shims to From impls#358
Closed
lgahdl wants to merge 1 commit into
Closed
refactor(sdk): convert bind-macro error/level shims to From impls#358lgahdl wants to merge 1 commit into
lgahdl wants to merge 1 commit into
Conversation
nexum-sdk's bind_host_via_wit_bindgen! emitted convert_chain_err, convert_fault, sdk_fault_into_wit, and convert_level as named functions for pure, infallible type-to-type conversions, so call sites read .map_err(sdk_fault_into_wit) instead of plain ?. All four become From impls instead - orphan-rule-allowed because the macro always expands in the per-cdylib module crate, where the wit-bindgen type is local and covers the From<T> type parameter. Ripples to every module lib.rs call site (twap-monitor, ethflow-watcher, http-probe, stop-loss, price-alert, balance-tracker) and to shepherd-sdk's own bind_cow_host_via_wit_bindgen!, which called convert_fault internally. No behavior change. Fixes nullislabs#264.
This was referenced Jul 16, 2026
Contributor
|
Closing as superseded by #452, which lands the same #264 refactor - the #358 predates the train and targets Reopen if landing this directly on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #264, #286. Follow-up to #185's chain-log WIT boundary cleanup, which converted
assemble_log/project_chain_logintoFromimpls under the "verb-named conversions should beFrom" idiom.nexum-sdk'sbind_host_via_wit_bindgen!still emitted four pure, infallible type-to-type conversions as named functions (convert_chain_err,convert_fault,sdk_fault_into_wit,convert_level— the issue's text names three of these under an older pre-rename naming,convert_err/sdk_err_into_wit; the fourth,convert_chain_err, was added since but is the same shape), so call sites read.map_err(sdk_fault_into_wit)instead of plain?.All four become
Fromimpls instead. This is orphan-rule-allowed because the macro always expands inside the per-cdylib module crate, where the wit-bindgen-generated type is local and either sits asSelfor covers theFrom<T>type parameter — exactly the mechanism #185 already established.Also closes #286: that issue asked for exactly
From/TryFrombetween the wit-bindgenFaultand the SDKFault— filed against the pre-shim state where call sites converted "by hand" (beforeconvert_fault/sdk_fault_into_witexisted as named functions). Theimpl From<nexum::host::types::Fault> for $crate::host::Faultand its reverse added here are exactly that conversion, done idiomatically. No separate work needed.Ripples to:
lib.rscall site:twap-monitor,ethflow-watcher,http-probe,stop-loss,price-alert,balance-tracker—.map_err(sdk_fault_into_wit)?becomes plain?(the enclosing fn'sErrtype already is the wit-localFault, so?auto-converts via the newFromimpl).shepherd-sdk's ownbind_cow_host_via_wit_bindgen!, whoseconvert_cow_errcalledconvert_fault(f)internally — updated tof.into(). (convert_cow_erritself is left as a named function; it's a different file/pattern not named by this issue.)No behavior change — pure ergonomics/idiom, as scoped in the issue.
Test plan
cargo build --release --target wasm32-wasip2for all 12 guest modules — cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings— cleancargo fmt --all -- --check— cleancargo test --workspace --all-features --locked— full suite green, all doctests pass