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
impl EmojiBuilder
Sourcepub fn new(name: &str) -> Self
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?
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}Sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Sets the description on the text block.
Examples found in repository?
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}Sourcepub fn add_todo(self, key: &str, value: &str) -> Self
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?
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}Sourcepub fn add_image_rgba(self, width: u32, height: u32, rgba: Vec<u8>) -> Self
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?
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}Sourcepub fn with_agent_lifecycle(self) -> Self
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?
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}Sourcepub fn encryption(self, encryption: EncryptionBlock) -> Self
pub fn encryption(self, encryption: EncryptionBlock) -> Self
Adds an encryption directive (which algorithm, which block types to encrypt at rest).
Sourcepub fn build(self) -> Emoji
pub fn build(self) -> Emoji
Finishes building. Infallible by design (see type docs).
Examples found in repository?
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
impl Clone for EmojiBuilder
Source§fn clone(&self) -> EmojiBuilder
fn clone(&self) -> EmojiBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more