Skip to content

refactor parse_url: replace builder_opts! with a builder trait#678

Draft
Kinrany wants to merge 1 commit intoapache:mainfrom
Kinrany:push-tsuyyuxtmqvt
Draft

refactor parse_url: replace builder_opts! with a builder trait#678
Kinrany wants to merge 1 commit intoapache:mainfrom
Kinrany:push-tsuyyuxtmqvt

Conversation

@Kinrany
Copy link
Copy Markdown
Contributor

@Kinrany Kinrany commented Mar 24, 2026

Which issue does this PR close?

Purely internal, probably not worth being included in the logs?

Rationale for this change

I'd like to be able to represent object store locations as URLs (with bidirectional conversions), so I was reading the parse_url implementation.

I noticed that the builder_opts! macro only exists because of the need to be generic over the builder types. So I replaced it with a trait that can create a builder from a URL and options.

What changes are included in this PR?

New private trait FromUrlBuilder with provided method build_from_url_and_options.

It can be implemented for any builder that:

  • has a default constructor
  • allows setting a URL
  • allows setting key-value configuration options
  • can be built, producing crate::Result<Box<dyn ObjectStore>>

Implemented for AWS, GCP, Azure, HTTP.

Are there any user-facing changes?

No user-facing changes whatsoever.

It might make sense to include the trait in the public API in the future. Not sure.

I named it FromUrlBuilder to limit scope, but I can see it being used more generally since a lot of the builder code is so similar.

Comment on lines -218 to +207
let url = &url[..url::Position::BeforePath];
builder_opts!(crate::http::HttpBuilder, url, _options)
let url: Url = url[..url::Position::BeforePath]
.parse()
.expect("URL with empty path and no query or fragment must still be a valid URL");
crate::http::HttpBuilder::build_from_url_and_options(&url, _options)?
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hopefully I'm not crazy and the logic here is valid.

@Kinrany Kinrany marked this pull request as draft March 24, 2026 20:31
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.

1 participant