-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extension methods to Url #2016
base: main
Are you sure you want to change the base?
Conversation
@JeffreyRichter @RickWinter what do you think? We're going to call this a lot in generated clients especially, but do we really want to extend the public API for that? If we were ever to replace Given that, I'm tempted not to provide this for now, but wanted to put it out there. Even if we did replace |
I agree with you -- I would NOT provide this for now (and probably never provide it). |
I'm in agreement on not adding this right now. |
@JeffreyRichter do you mean the methods, or the type? We have to expose the It's just that This isn't a question for beta.1, but pre-GA. I'm leaning toward at least newtyping it and expose those methods we want, which also means abstracting some things like |
BTW: the fact that these are public is the same problem as in other languages: they are defined in a crate for other crates to use so they have to be public but are intended for internal use. We could always document them as such, though we'd still not be able to break them...at least as easily; we can always bump dependency versions as needed and ship new dependent crates. |
I meant the (extension) methods. We could provide the methods but not as extension? |
I mean, that's why extension methods largely exist in many languages. Even in Rust they define "extension" methods (no official name I've seen, but everyone calls them "extension methods") for types - mainly traits - outside their definition precisely because they can't modify the definition. I see no functionality equivalent between top-level functions and extension methods apart from making extension methods easier to discover e.g., rust-analyzer would suggest them and auto-import functions. Is that the only part you don't like then? |
I'm sure my lack of rust knowledge is affecting me here. If the url type is our type, then why would we need extension methods? Can't they just be methods on the type itself? To me, we either have formal methods that are past or the type of we have methods that are not past of the type. It seems strange to me to own the type and the methods but link them information together by extension methods as opposed to formal methods. But, if this is idiomatic for rust, then I can concede this. |
@JeffreyRichter I think we're getting wires crossed here. I was describing why I'm declaring extension methods now, but also stating I think we should take ownership of That said, yes, there's still a reason for extension methods even for types you own and it has to do with scope. Less-used or narrowly-scoped methods might be extension methods. Not saying we have to do that, though in this case there may be good reason since only our clients I'd expect to rewrite URLs while callers would more likely just want to extract data from them to make entirely new URLs. |
Relates to Azure/typespec-rust#226