Skip to main content

substrate_data/schema/convert/
write.rs

1//! A schema's value out: to the binary form, to text.
2
3use crate::binary::Writer;
4use crate::schema::Schema;
5use crate::text;
6
7/// `v` in the binary form, written straight ([`Schema::encode`]).
8pub fn to_bytes<T: Schema>(v: &T) -> Vec<u8> {
9    let mut w = Writer::new();
10    v.encode(&mut w);
11    w.finish()
12}
13
14/// `value` as text, indented.
15pub fn to_text<T: Schema>(value: &T) -> String {
16    text::to_string_pretty(&value.write())
17}