pub struct EmojiExporter;Expand description
Stateless serializer/deserializer for Emoji.
Implementations§
Source§impl EmojiExporter
impl EmojiExporter
Sourcepub fn to_binary(emoji: &Emoji) -> Result<Vec<u8>>
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}Sourcepub fn to_binary_encrypted(emoji: &Emoji, keyring: &KeyRing) -> Result<Vec<u8>>
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.
Sourcepub fn from_binary(bytes: &[u8]) -> Result<Emoji>
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}Sourcepub fn from_binary_decrypted(bytes: &[u8], keyring: &KeyRing) -> Result<Emoji>
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).
Sourcepub fn to_unicode(emoji: &Emoji) -> Result<String>
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}Sourcepub fn from_unicode(s: &str) -> Result<Emoji>
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§
impl Freeze for EmojiExporter
impl RefUnwindSafe for EmojiExporter
impl Send for EmojiExporter
impl Sync for EmojiExporter
impl Unpin for EmojiExporter
impl UnsafeUnpin for EmojiExporter
impl UnwindSafe for EmojiExporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more