Skip to content

Comment on Building a Discord bot in Rustparent

Comments

The type in question has since been renamed to CommandDataOption, as well as other such long types (https://github.com/serenity-rs/serenity/pull/1899).

With forced functional programming, you may be referring to serenity's builders? For example

    .send_message(|m| m
        .content("text")
        .embed(|e| e
            .description("...")
            .timestamp("...")
        )
        .components(|c| c
            .create_action_row(|r| r
                .create_button(|b| b
                    .style(ButtonStyle::Primary)
                    .label("press me")
                    .custom_id("button1")
                )
            )
        )
    ).await?;
In the next breaking release (`next` branch in git), we have a new by-value builder style which has turned out to be a better design in many ways:
    .send_message(CreateMessage::new()
        .content("text")
        .embed(CreateEmbed::new()
            .description("...")
            .timestamp("...")
        )
        .components(CreateComponents::new()
            .add_action_row(CreateActionRow::new()
                .add_button(
                    CreateButton::new(ButtonStyle::Primary, "button1").label("press me")
                )
            )
        )
    )
And a PR is open to make the API even better (replace redundant CreateComponents with Vec<CreateActionRow>) and more will be coming presumably.

Does this seem more rusty to you? We're open to more criticism - developmenet on serenity is quite active currently (e.g. 52 PRs merged in the last month)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.