Skip to main content

EmojiBuilder

Struct EmojiBuilder 

Source
pub struct EmojiBuilder { /* private fields */ }
Expand description

Fluent builder. build() is infallible: validation happens in the add_* methods, which repair inconsistent input (documented per method) instead of panicking.

Implementations§

Source§

impl EmojiBuilder

Source

pub fn new(name: &str) -> Self

Starts a builder; every emoji carries a text block so the name round-trips through the binary/unicode containers.

Examples found in repository?
examples/build_emoji.rs (line 6)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}
Source

pub fn description(self, description: &str) -> Self

Sets the description on the text block.

Examples found in repository?
examples/build_emoji.rs (line 7)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}
Source

pub fn add_todo(self, key: &str, value: &str) -> Self

Adds a todo item (status Pending), appending to an existing todo block when present.

Examples found in repository?
examples/build_emoji.rs (line 8)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}
Source

pub fn add_image_rgba(self, width: u32, height: u32, rgba: Vec<u8>) -> Self

Adds a single-frame image block from raw RGBA8 pixels. If rgba does not match width * height * 4 it is zero-padded/truncated to fit (the builder never panics; strict validation lives in SpriteAtlas::validate).

Examples found in repository?
examples/build_emoji.rs (line 9)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}
Source

pub fn with_agent_lifecycle(self) -> Self

Adds the default agent lifecycle: idle (initial), active, sleeping, with wake/sleep/activate/deactivate transitions.

Examples found in repository?
examples/build_emoji.rs (line 10)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}
Source

pub fn encryption(self, encryption: EncryptionBlock) -> Self

Adds an encryption directive (which algorithm, which block types to encrypt at rest).

Source

pub fn add_block(self, block: Block) -> Self

Appends any block.

Source

pub fn build(self) -> Emoji

Finishes building. Infallible by design (see type docs).

Examples found in repository?
examples/build_emoji.rs (line 11)
5fn main() {
6    let emoji = EmojiBuilder::new("my-emoji")
7        .description("An emoji that does things")
8        .add_todo("task1", "Build the thing")
9        .add_image_rgba(64, 64, vec![0u8; 64 * 64 * 4])
10        .with_agent_lifecycle()
11        .build();
12
13    let binary = EmojiExporter::to_binary(&emoji).expect("to_binary");
14    let unicode = EmojiExporter::to_unicode(&emoji).expect("to_unicode");
15
16    println!("emoji:      {}", emoji.name);
17    println!("blocks:     {}", emoji.blocks.len());
18    println!("binary:     {} bytes", binary.len());
19    println!("unicode:    {} chars", unicode.chars().count());
20
21    let back = EmojiExporter::from_binary(&binary).expect("from_binary");
22    assert_eq!(emoji, back, "binary round-trip");
23    let back = EmojiExporter::from_unicode(&unicode).expect("from_unicode");
24    assert_eq!(emoji, back, "unicode round-trip");
25    println!("round-trip: ok");
26}

Trait Implementations§

Source§

impl Clone for EmojiBuilder

Source§

fn clone(&self) -> EmojiBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmojiBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.