Skip to content

Make InlineStr From<&T> infallible and non-panicking#6

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-from-impl-in-inline-str
Draft

Make InlineStr From<&T> infallible and non-panicking#6
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-from-impl-in-inline-str

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown

InlineStr had a From<&T> implementation that could panic on oversized input, violating From’s infallibility contract. This change removes that panic path and aligns behavior with other infallible InlineStr conversions.

  • Problem alignment

    • Replaces fallible behavior in From<&T> (expect(...) on try_from) with an infallible conversion strategy.
  • Conversion semantics

    • impl<T: AsRef<str>> From<&T> for InlineStr now:
      • copies bytes into the fixed inline buffer
      • truncates to MAX_INLINE_STR_LEN
      • never panics
  • Coverage added

    • Added focused tests for oversized references converted via From<&T>:
      • &str reference path
      • &String reference path
    • Both assert truncation to inline capacity.
impl<T: AsRef<str>> From<&T> for InlineStr {
  fn from(s: &T) -> Self {
    let src = s.as_ref().as_bytes();
    let len = src.len().min(MAX_INLINE_STR_LEN);
    let mut buf = [0u8; MAX_INLINE_STR_LEN];
    buf[..len].copy_from_slice(&src[..len]);
    Self { buf, len: len as u8 }
  }
}

Copilot AI changed the title [WIP] Fix From impl in inline_str.rs to ensure compliance Make InlineStr From<&T> infallible and non-panicking Jun 17, 2026
Copilot AI requested a review from nberlette June 17, 2026 12:45
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