Skip to main content
PollCard is a builder pattern for rendering a styled poll image as a Vec<u8> PNG, ready to send as a file attachment.

Setup

Add to Cargo.toml:

Limits

render_png() will return an error if the options count is empty or exceeds 7 items.

Creating

PollCard::new

Creates a new poll card with the given title displayed in the header.

Methods

option

Appends a new option to the poll with the given label and votes count. The percentages and progress bars are calculated automatically based on the total sum of votes across all options.
You can call this method up to 7 times. Exceeding this limit will cause render_png() to fail.

header_label

Sets the small label above the main title. Defaults to "POLL".

votes_label

Sets the word appended after the total vote count in the footer. Defaults to "votes".

render_png

Renders the currently built card into a PNG image. The result is a standard Vec<u8> that can be attached as a file.

Example

Simple usage


Full Bot Example

A complete minimal bot implementing a !poll command. The bot dynamically updates the image in place using edit_files as users react to vote.
Cargo.toml