Skip to content

[PR #28] #[async_trait] macro on edition-2024 workspace — native AFIT preferred #71

@obchain

Description

@obchain

PR: #28 (feat/03-lending-protocol-trait)
File: crates/charon-core/src/traits.rs, line 19; Cargo.toml line 34

Workspace declares edition = "2024" (Rust 1.85). Native async-fn-in-trait stable since 1.75. #[async_trait] boxes every future (Pin<Box<dyn Future + Send>>), adds heap alloc per call, and forces dyn-compatible lifetime. Hot path is fetch_positions called per block — boxing cost is measurable.

Native AFIT caveat: async fn in trait is object-safe only with return_type_notation or impl Trait bounds. For Arc<dyn LendingProtocol> use, either (a) keep #[async_trait] with a rustdoc comment explaining the dyn requirement, or (b) use the newer trait_variant::make / AsyncLendingProtocol split.

Fix: Choose one:

  1. Keep #[async_trait] but document why in trait rustdoc.
  2. Switch to native AFIT + trait_variant::make(Send) pattern.
  3. Drop dyn requirement; accept impl LendingProtocol generics throughout.

Default to option 1 for now (simplest), revisit when dyn overhead shows in profiling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polish

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions