Skeleton code of what will eventually become a procedural macro library for embedding fluent files as static rust.
O77KA6C4UJGZXVGPEA7WCRQH6XYQJPWETSPDXI3VOKOSRQND7JEQC use fluent_syntax::ast::{Entry, Message, Resource};#[derive(Debug)]enum GroupEntry<'resource> {Message(&'resource Message<&'resource str>),}#[derive(Debug)]pub struct Group<'resource> {children: Vec<GroupEntry<'resource>>,}impl<'resource> TryFrom<&'resource Entry<&'resource str>> for GroupEntry<'resource> {type Error = ();fn try_from(value: &'resource Entry<&'resource str>) -> Result<Self, Self::Error> {match value {Entry::Message(message) => Ok(Self::Message(message)),_ => Err(()),}}}impl<'resource> Group<'resource> {pub fn from_resource(resource: &'resource Resource<&'resource str>) -> Self {let mut children = Vec::new();for entry in &resource.body {let matched_entry = GroupEntry::try_from(entry).unwrap();children.push(matched_entry);}Self { children }}}
use fluent_embed::Group;fn main() {let ftl = r"greeting = hello!";let resource = fluent_syntax::parser::parse(ftl).unwrap();let group = Group::from_resource(&resource);dbg!(group);}
[package]name = "fluent_embed"version = "0.1.0"edition = "2021"[lints]workspace = true[dependencies]fluent-syntax = "0.11.0"heck = { version = "0.4.1", features = ["unicode"] }proc-macro2 = "1.0.78"quote = "1.0.35"syn = { version = "2.0.48", features = ["full"] }
[[package]]name = "fluent-syntax"version = "0.11.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c0abed97648395c902868fee9026de96483933faa54ea3b40d652f7dfe61ca78"dependencies = ["thiserror",][[package]]name = "fluent_embed"version = "0.1.0"dependencies = ["fluent-syntax","heck","proc-macro2","quote","syn",]
[[package]]name = "unicode-segmentation"version = "1.10.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"