Crates.io | fluent-serde |
lib.rs | fluent-serde |
version | 0.1.0 |
source | src |
created_at | 2021-10-20 09:21:32.162187 |
updated_at | 2021-10-20 09:21:32.162187 |
description | Serializer implementations for FluentValue and FluentArgs |
homepage | |
repository | https://github.com/chitoyuu/fluent-serde |
max_upload_size | |
id | 467804 |
size | 31,900 |
Provides third-party serde
implementations for fluent
argument and value types.
This crate is not affiliated with Mozilla or Project Fluent in any way.
[dependencies]
fluent = "0.16.0"
fluent-serde = "0.1.0"
use std::borrow::Cow;
use fluent::FluentValue;
use fluent::types::{FluentNumber, FluentNumberOptions};
use fluent_serde::ser::ArgsSerializer;
use serde::Serialize;
#[derive(Serialize)]
struct Foo {
foo: i32,
}
#[derive(Serialize)]
struct Bar {
bar: String,
}
let mut ser = ArgsSerializer::new();
Foo { foo: 42 }.serialize(&mut ser);
Bar { bar: "bar".into() }.serialize(&mut ser);
let args = ser.done();
assert_eq!(
&FluentValue::Number(FluentNumber::new(42.0, FluentNumberOptions::default())),
args.get("foo").unwrap(),
);
assert_eq!(
&FluentValue::String(Cow::Owned("bar".into())),
args.get("bar").unwrap(),
);
MIT OR Apache-2.0