Skip to main content

EmojiExporter

Struct EmojiExporter 

Source
pub struct EmojiExporter;
Expand description

Stateless serializer/deserializer for Emoji.

Implementations§

Source§

impl EmojiExporter

Source

pub fn to_binary(emoji: &Emoji) -> Result<Vec<u8>>

Serializes to the .cmse binary container (plaintext).

Examples found in repository?
examples/build_emoji.rs (line 13)
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 to_binary_encrypted(emoji: &Emoji, keyring: &KeyRing) -> Result<Vec<u8>>

Serializes to .cmse, encrypting every block type named by the emoji’s Enc block with keyring.

Source

pub fn from_binary(bytes: &[u8]) -> Result<Emoji>

Parses a .cmse container. Fails if any block is encrypted.

Examples found in repository?
examples/build_emoji.rs (line 21)
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 from_binary_decrypted(bytes: &[u8], keyring: &KeyRing) -> Result<Emoji>

Parses a .cmse container, decrypting encrypted blocks with keyring (plaintext containers are accepted too).

Source

pub fn to_unicode(emoji: &Emoji) -> Result<String>

Encodes to the Unicode envelope string (plane 15/16 PUA + tag chars). Always plaintext — encrypt bytes first if a confidential text-channel transport is needed.

Examples found in repository?
examples/build_emoji.rs (line 14)
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 from_unicode(s: &str) -> Result<Emoji>

Decodes every block envelope found in s (other text is skipped).

Examples found in repository?
examples/build_emoji.rs (line 23)
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}

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> 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, 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.