Skip to content

gix-url: accept impl Into<&BStr> in parse#2606

Closed
Sarthak Bhardwaj (SarthakB11) wants to merge 4 commits into
GitoxideLabs:mainfrom
SarthakB11:fix/issue-2468
Closed

gix-url: accept impl Into<&BStr> in parse#2606
Sarthak Bhardwaj (SarthakB11) wants to merge 4 commits into
GitoxideLabs:mainfrom
SarthakB11:fix/issue-2468

Conversation

@SarthakB11
Copy link
Copy Markdown
Contributor

Per #2468, gix_url::parse now takes impl Into<&'a BStr> instead of &BStr. A &bstring borrow now suffices at the call site; existing &BStr callers keep compiling via the reflexive From<&BStr> for &BStr impl in bstr. String literals also work directly through From<&str> for &BStr.

The signature widens to a borrowed Into (Into<&'a BStr>) rather than the owned Into<BString> shape the issue mentions, because callers in this codebase already hold borrowed bstrs and the borrowed form avoids an allocation. The bstr re-export question raised in the same issue is out of scope here; happy to follow up.

One internal .as_ref() had to become .as_bstr() because BString exposes several AsRef impls and the call was ambiguous after the signature change. Doc-test examples were left passing literals directly.

Validation

  • cargo test -p gix-url
  • cargo check --workspace
  • cargo doc -p gix-url (doc-test examples)

Disclosure

This PR was drafted with Claude Code (Anthropic). I reviewed and verified the diff before submission.

Closes #2468

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7bd84ba539

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread gix-url/src/lib.rs
/// We cannot and should never have to deal with UTF-16 encoded windows strings, so bytes input is acceptable.
/// For file-paths, we don't expect UTF8 encoding either.
pub fn parse(input: &BStr) -> Result<Url, parse::Error> {
pub fn parse<'a>(input: impl Into<&'a BStr>) -> Result<Url, parse::Error> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep existing .into() call sites compiling

With the parameter changed to a generic impl Into<&'a BStr>, existing callers that already wrote gix_url::parse("...".into()) no longer give the compiler a concrete target type for the inner .into(), so type inference fails with “cannot infer type” rather than selecting &BStr. This pattern still exists in this crate's tests (for example gix-url/tests/url/access.rs uses both string and byte-slice .into() inputs), and it is also a likely downstream call style from the previous API, so this signature change breaks those callers unless every call site removes .into() or the API keeps a concrete input type.

Useful? React with 👍 / 👎.

`BString::as_bstr` is private in some bstr feature configurations
(notably the fuzz crate), which broke CI Build Fuzzers. `BStr::new()`
is always public and serves the same purpose.
`parse(impl Into<&'a BStr>)` makes `data.into()` ambiguous; use
`data.as_bstr()` via `bstr::ByteSlice` for an unambiguous `&BStr`.
`parse(impl Into<&'a BStr>)` accepts `&[u8]` directly via the
`From<&[u8]> for &BStr` impl in bstr. The previous `.into()` was
ambiguous after the signature widened.
@SarthakB11
Copy link
Copy Markdown
Contributor Author

Closing this for now. After pushing, CI surfaced ambiguous .into() calls in ~34 downstream sites (multiple tests in gix-url/tests/, plus gix-transport, gix/repository/remote.rs, etc.) — the impl Into<&'a BStr> widening can't resolve data.into() without explicit annotations, so a clean version needs either a larger sweep of the call sites or a different signature shape.

Two questions before I retry, if you have a preference:

  1. Owned impl Into<BString> (as the issue title literally reads) vs borrowed impl Into<&'a BStr> vs AsRef<[u8]> — each has different ergonomic trade-offs around allocations and downstream .into() compat.
  2. The issue's secondary point — "bstr is not reexported" — would a pub use bstr::{BStr, BString}; from gix_url be welcome alongside (or instead of) the parse signature change?

Happy to take either direction. Closing this draft so the issue stays the discussion point.

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.

Take impl Into<Bstr> in gix_url::parse

1 participant