Skip to content

451#456

Merged
RAprogramm merged 1 commit into
mainfrom
451
Jul 5, 2026
Merged

451#456
RAprogramm merged 1 commit into
mainfrom
451

Conversation

@RAprogramm

Copy link
Copy Markdown
Owner

Closes #451

Implements real AppError::downcast and downcast_mut (both were stubs that unconditionally failed).

Design

  • Source storage becomes StoredSource: Owned(Box<dyn Error + Send + Sync>) / Shared(Arc<...>). Needed because an Arc<dyn Error> can never yield exclusive ownership in safe Rust (try_unwrap requires Sized), and the crate forbids unsafe.
  • downcast::<E>(self) -> Result<Box<E>, Self>: succeeds for an owned immediate source of type E; on failure the error is returned fully intact (box reinserted). Shared sources always return Err — documented with rationale (anyhow does this with unsafe; we don't).
  • downcast_mut::<E>(): owned → mutable box downcast; shared → Arc::get_mut (unique reference only, mirroring anyhow 1.0.103's soundness semantics). No unsafe anywhere.
  • is/downcast_ref semantics unchanged (immediate source); with_source now stores owned, with_source_arc shared — ownership caveats documented; ResultExt::context sources become downcastable as a bonus.

Tests

15 new tests: owned success, wrong-type Err with error intact, shared-Arc Err with strong_count preserved, unique-Arc downcast_mut success, shared-Arc None, mutation visible via downcast_ref, interplay of with_source / with_source_arc / with_context. Stub-era tests replaced. Full suite, doctests (173), no_std build, clippy zero warnings, nightly fmt — all green.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@RAprogramm RAprogramm merged commit ed5a512 into main Jul 5, 2026
29 checks passed
@RAprogramm RAprogramm deleted the 451 branch July 5, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement AppError::downcast and downcast_mut (currently stubs)

1 participant