Skip to content

feat(rs-client): Make Usecase::from_static a const fn - #712

Merged
jan-auer merged 4 commits into
mainfrom
feat/rust-client-const-from-static
Oct 30, 2026
Merged

jan-auer merged 4 commits into
mainfrom
feat/rust-client-const-from-static

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Makes Usecase::from_static a const fn, so an invalid name fails compilation when it's evaluated in a const context, and a Usecase can live in a plain static without LazyLock:

static ATTACHMENTS: Usecase = Usecase::from_static("attachments");  // ok
static BROKEN: Usecase = Usecase::from_static("attachments/v2");     // compile error

Outside a const context it still panics at runtime, as before, now reporting the caller's location.

Most of the change is in objectstore_types::usecase::Usecase. It now stores either a &'static str or an Arc<str> and gains a const fn from_static alongside new, with validation kept private to the module. Arc::new can't run in a const fn, so this is what makes a const constructor possible. Equality, ordering, hashing, serialization, and Debug use the name string, so static and dynamic names behave the same.

Since validation runs in a const fn, InvalidUsecaseName::InvalidChar now reports the byte position of the first invalid character instead of the character, which keeps validation free of UTF-8 decoding. Usecase::new in the types crate takes impl AsRef<str> instead of impl Into<String> and allocates the name once.

The client only swaps its Arc<UsecaseName> field for UsecaseName and forwards from_static to the types crate.

Changelog Entry

  • Usecase::from_static is now a const fn
    • A Usecase can be a plain static without LazyLock, and an invalid name fails at compile time when evaluated in a const context.
    • InvalidUsecaseName::InvalidChar now holds the byte position of the invalid character instead of the character.

via @lcian.

--

View Junior Session [Sentry]

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.15596% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.50%. Comparing base (764b52c) to head (fd73290).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
objectstore-types/src/usecase.rs 84.94% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #712      +/-   ##
==========================================
- Coverage   91.55%   91.50%   -0.05%     
==========================================
  Files         116      116              
  Lines       22088    22175      +87     
==========================================
+ Hits        20222    20292      +70     
- Misses       1866     1883      +17     
Components Coverage Δ
Rust Backend 94.68% <84.94%> (-0.06%) ⬇️
Rust Client 84.41% <100.00%> (+0.12%) ⬆️
Python Client 93.88% <ø> (ø)

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from feat/rust-client-usecase-from-static to main October 22, 2026 12:02
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Semver Impact of This PR

This PR lands in these workspaces:

  • clients/rust: 🟡 Minor (new features)
📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features

  • Usecase::from_static is now a const fn by lcian and jan-auer with sentry-junior in #712
    • A Usecase can be a plain static without LazyLock, and an invalid name fails at compile time when evaluated in a const context.
    • InvalidUsecaseName::InvalidChar now holds the byte position of the invalid character instead of the character.
  • via @lcian. by lcian and jan-auer with sentry-junior in #712
  • -- by lcian and jan-auer with sentry-junior in #712
  • View Junior Session [Sentry] by lcian and jan-auer with sentry-junior in #712

🤖 This preview updates automatically when you update the PR.

objectstore-types' Usecase now stores either a &'static str or an Arc<str>
and gains a const fn from_static, with validation kept private. The client
forwards to it, so an invalid name in a const or static fails compilation.

Co-Authored-By: Lorenzo Cian <17258265+lcian@users.noreply.github.com>
@sentry-junior
sentry-junior Bot force-pushed the feat/rust-client-const-from-static branch from 9120ce9 to 3c17f7e Compare October 30, 2026 10:30
@jan-auer
jan-auer marked this pull request as ready for review October 30, 2026 11:42
@jan-auer
jan-auer requested a review from a team as a code owner October 30, 2026 11:42
InvalidUsecaseName::InvalidChar now carries the byte position of the first invalid
character instead of the decoded char, so const validation needs no UTF-8 decoder. Error
messages live in shared constants used by both the Display impl and the const panics in
from_static, which now has #[track_caller].

Usecase::new takes impl AsRef<str> and allocates the Arc<str> once, deserialization
reads the string through a visitor instead of an intermediate String, and Debug prints the
name without the internal storage variant. The client's constructors share one with_name
helper, and from_static gains doc examples, including a compile_fail check.

BREAKING CHANGE: InvalidUsecaseName::InvalidChar holds a usize byte position instead
of a char, and Usecase::new accepts impl AsRef<str> instead of impl Into<String>.
@jan-auer
jan-auer enabled auto-merge (squash) October 30, 2026 12:38
@jan-auer
jan-auer merged commit 1c2db3b into main Oct 30, 2026
26 checks passed
@jan-auer
jan-auer deleted the feat/rust-client-const-from-static branch October 30, 2026 12:43
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.

2 participants