Enum rsbadges::Style

source ·
pub enum Style {
    Plastic(Badge),
    Flat(Badge),
    FlatSquare(Badge),
    ForTheBadge(Badge),
    Social(Badge),
}
Expand description

A badge container used to format and generate a badge SVG.

As the Badge struct holds generic badge data, the Style enum instructs how to generate that data into a badge SVG. There are currently five Styles: Plastic, Flat, FlatSquare, ForTheBadge, and Social. This naming follows the convention set by Shields.io.

Once a Style object has been instantiated, a badge can be created using the generate_svg function.

Examples

use rsbadges::{Badge, Style};
let badge = Badge {
    label_text: String::from("Custom_label"),
    msg_text: String::from("Custom_msg"),
    ..Badge::default()
};
// Create a plastic badge using the data created above.
let badge_style = Style::Plastic(badge);
let badge_svg = badge_style.generate_svg();
// Save this to file with rsbadges::save_svg

Variants§

§

Plastic(Badge)

The “plastic” badge style

§

Flat(Badge)

The “flat” badge style

§

FlatSquare(Badge)

The “flat square” badge style

§

ForTheBadge(Badge)

The “for the badge” badge style

§

Social(Badge)

The “social” badge style

Implementations§

source§

impl Style

source

pub fn generate_svg(&self) -> Result<String, BadgeError>

Generates an SVG from the badge data in the chosen badge style.

Badges are lazily evaluated; that is, the data in the Badge struct is not verified until a badge is generated using this function.

Errors

Since this is where data verification takes place, a number of errors are possible:

See BadgeError for a full description of each.

Trait Implementations§

source§

impl Debug for Style

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V