jsonptr icon indicating copy to clipboard operation
jsonptr copied to clipboard

improve `Token::from_encoded`

Open asmello opened this issue 9 months ago • 1 comments

Non-breaking change. Accept owned or borrowed strings as input in Token::from_encoded.

asmello avatar Feb 23 '25 16:02 asmello

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.8%. Comparing base (29840e7) to head (7e5bf35).

Additional details and impacted files
Files with missing lines Coverage Δ
src/token.rs 98.7% <100.0%> (+<0.1%) :arrow_up:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Feb 23 '25 16:02 codecov-commenter

This is breaking but probably pretty uncommon. A type could implement Deref<Target = str> but not Into<Cow<str>>

struct X;

impl std::ops::Deref for X {
    type Target = str;
    fn deref(&self) -> &Self::Target { "" }
}

fn ok(v: &str) {}
fn breaking<'a>(v: impl Into<std::borrow::Cow<'a, str>>) {}

fn main() {
    ok(&X);
    breaking(&X);
}

playground link

If memory serves, we have breaking changes in main already so I'm pulling it in.

chanced avatar Jun 02 '25 23:06 chanced

Huh, fascinating! I honestly didn't know Deref worked like that! I thought the only type that satisfied a &str signature was, well, &str.

In that case, let's document this as breaking accordingly and make sure to include in the next minor release. Thanks for flagging.

asmello avatar Jun 08 '25 18:06 asmello

Actually, I think the changelog is fine as is. Since we have harder unreleased breaks, I'll assume you're ok with this and will proceed with merging.

asmello avatar Jun 08 '25 18:06 asmello