Skip to content
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

Feature request: provide separate struct for URL which is can-be-base #909

Open
kriomant opened this issue Feb 24, 2024 · 0 comments
Open

Comments

@kriomant
Copy link

Suppose you write client for some REST service:

struct Client { url: Url }
impl Client {
    fn get_smth(&self) -> Result<Smth> {
        let mut url = self.url.clone();
        url.path_segments_mut().unwrap()  // <---- HERE
            .push("segment");
    }
}

The problem is that almost every client method would have to manipulate URL, e.g. add path segments, but these methods may return error for 'cannot-be-base' URLs. So you either have to propagate this error or use unwrap, both ways are so-so.

It would be convenient to have separate type for URLs which are always can-be-base. You convert URL to this BaseURL once, pass it to client and client is sure that URL-manipulation methods are infallible.

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

No branches or pull requests

1 participant