Skip to content

sdk: convert the bind-macro error/level shims to From impls #264

Description

@mfw78

Follow-up to the chain-log WIT boundary cleanup (PR #185, commit 5c68311), which converted assemble_log and project_chain_log into From impls under the "verb-named conversions should be From" idiom.

Problem

Three verb-named converters remain in the bind macro (crates/nexum-sdk/src/wit_bindgen_macro.rs):

  • convert_err (wit HostError -> sdk HostError)
  • sdk_err_into_wit (sdk HostError -> wit HostError)
  • convert_level (tracing Level -> wit logging::Level)

Each is a pure, infallible type-to-type conversion expressed as a named function, so call sites read .map_err(convert_err) instead of ? / .map_err(Into::into).

Proposed

Emit each as a From impl in the macro. This is orphan-rule-allowed because the macro expands in the per-cdylib module crate, where the wit type is local and can sit as the Self (or trait-param) side:

  • impl From<HostError> for $crate::host::HostError
  • impl From<$crate::host::HostError> for HostError (its _ => Internal wildcard for the #[non_exhaustive] sdk enum is fine inside From)
  • impl From<$crate::Level> for nexum::host::logging::Level (body stays the if ladder since tracing_core::Level is a const set, not an enum)

Scope / cost

Ripples to every module lib.rs .map_err(convert_err) / sdk_err_into_wit / convert_level call site, so it is its own focused PR rather than part of the chain-log change. No behaviour change; pure ergonomics/idiom.

Metadata

Metadata

Assignees

Labels

component/sdknexum-sdk / shepherd-sdk, proc macros, cargo-nexumdebtCode works but makes future work harder.dxDeveloper experience is suffering.effort/hoursFew hours. Single PR.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions