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

34 lines
924 B
Rust
Raw Normal View History

2021-08-02 09:42:48 +00:00
pub mod reader;
pub mod writer;
pub use reader::TextReader;
pub use writer::TextWriter;
2022-07-10 11:25:35 +00:00
use crate::value::source::BytesBinarySource;
2021-08-02 09:42:48 +00:00
use std::io;
2022-07-10 11:25:35 +00:00
use super::{DomainDecode, IOValue, IOValueDomainCodec, NestedValue, Reader};
2021-08-02 09:42:48 +00:00
2022-07-10 11:25:35 +00:00
pub fn from_str<N: NestedValue, Dec: DomainDecode<N::Embedded>>(
2021-08-02 09:42:48 +00:00
s: &str,
2022-07-10 11:25:35 +00:00
decode_embedded: &mut Dec,
2021-08-02 09:42:48 +00:00
) -> io::Result<N> {
2022-07-10 11:25:35 +00:00
TextReader::new(&mut BytesBinarySource::new(s.as_bytes())).demand_next(false, decode_embedded)
2021-08-02 09:42:48 +00:00
}
pub fn iovalue_from_str(s: &str) -> io::Result<IOValue> {
2022-07-10 11:25:35 +00:00
from_str(s, &mut IOValueDomainCodec)
2021-08-02 09:42:48 +00:00
}
2022-07-10 11:25:35 +00:00
pub fn annotated_from_str<N: NestedValue, Dec: DomainDecode<N::Embedded>>(
2021-08-02 09:42:48 +00:00
s: &str,
2022-07-10 11:25:35 +00:00
decode_embedded: &mut Dec,
2021-08-02 09:42:48 +00:00
) -> io::Result<N> {
2022-07-10 11:25:35 +00:00
TextReader::new(&mut BytesBinarySource::new(s.as_bytes())).demand_next(true, decode_embedded)
2021-08-02 09:42:48 +00:00
}
pub fn annotated_iovalue_from_str(s: &str) -> io::Result<IOValue> {
2022-07-10 11:25:35 +00:00
annotated_from_str(s, &mut IOValueDomainCodec)
2021-08-02 09:42:48 +00:00
}