Skip to content

Builder pattern + methods #47

Open
@Emilgardis

Description

@Emilgardis

Currently, this crate uses the builder pattern to assure a stable API i.e https://github.com/Emilgardis/twitch_api2/blob/e1ba9faff6c72b92f271a888b480a016c334b82a/src/helix/channels.rs#L82-L88

I decided to do it this way due to Twitch not guaranteeing a stable API themselves on documented items, so marking structs as #[non_exhaustive] and using a builder seems better.

However, sometimes this makes things harder to use, as typed-builder does not exactly make structs more accessible.

While this is done for stability, I feel like some structs don't lend themselves to the builder pattern, like the above example.

I want to solve this somehow, without sacrificing API stability.

To do that I think what needs to be done is creating methods for common usages of requests.

Example:

impl GetChannelInformationRequest {
    pub fn get_channel(broadcaster: String) -> GetChannelInformationRequest {
        GetChannelInformationRequest::builder().broadcaster_id(broadcaster).build()
    }
}

or for https://github.com/Emilgardis/twitch_api2/blob/e1ba9faff6c72b92f271a888b480a016c334b82a/src/helix/games.rs#L59-L68

impl GetGamesRequest  {
    pub fn get_game(id: types::CategoryId) -> GetGamesRequest {
        GetGamesRequest::builder().id(vec![id]).build()
    }
}

There is the crate derive_builder that could help also.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions