preserves/implementations/rust/preserves/src/value/text/mod.rs

34 lines
924 B
Rust

pub mod reader;
pub mod writer;
pub use reader::TextReader;
pub use writer::TextWriter;
use crate::value::source::BytesBinarySource;
use std::io;
use super::{DomainDecode, IOValue, IOValueDomainCodec, NestedValue, Reader};
pub fn from_str<N: NestedValue, Dec: DomainDecode<N::Embedded>>(
s: &str,
decode_embedded: &mut Dec,
) -> io::Result<N> {
TextReader::new(&mut BytesBinarySource::new(s.as_bytes())).demand_next(false, decode_embedded)
}
pub fn iovalue_from_str(s: &str) -> io::Result<IOValue> {
from_str(s, &mut IOValueDomainCodec)
}
pub fn annotated_from_str<N: NestedValue, Dec: DomainDecode<N::Embedded>>(
s: &str,
decode_embedded: &mut Dec,
) -> io::Result<N> {
TextReader::new(&mut BytesBinarySource::new(s.as_bytes())).demand_next(true, decode_embedded)
}
pub fn annotated_iovalue_from_str(s: &str) -> io::Result<IOValue> {
annotated_from_str(s, &mut IOValueDomainCodec)
}