munyo/
lib.rs

1#![allow(clippy::module_inception)]
2#![allow(clippy::tabs_in_doc_comments)]
3#![warn(unreachable_pub)]
4#![warn(unused_crate_dependencies)]
5#![warn(missing_docs)]
6
7//! Munyo is a language.
8//! Since the API documentation isn't enough to use it, I wrote various materials.
9//!
10//! See [readme](https://github.com/dochy-ksti/munyorunyoru/blob/master/readme.md)
11//! [samples](https://github.com/dochy-ksti/munyorunyoru/tree/master/munyo-sample/)
12//! [lang_spec](https://github.com/dochy-ksti/munyorunyoru/blob/master/lang_spec.txt)
13//! [What's DSL?](https://github.com/dochy-ksti/munyorunyoru/blob/master/whats_dsl.md)
14
15pub mod builder;
16pub mod error;
17pub mod file_io;
18pub mod lang;
19mod pub_apis;
20
21mod serde;
22#[cfg(test)]
23mod tests;
24
25#[doc(inline)]
26pub use crate::builder::default_builder::MunyoItem;
27pub use crate::file_io::concurrent::Concurrent;
28pub use crate::lang::from_str_with_metabuilder::from_str_with_metabuilder;
29pub use crate::pub_apis::{from_file, from_str, from_str_with_path, to_string};
30pub use crate::serde::deserializer::MunyoDeserializer;
31pub use crate::serde::rest_of::{IgnoredAnyVisitor, RestOf};
32pub use crate::serde::serializer::MunyoSerializer;
33
34pub use crate::error::munyo_error::Error;
35/// Result type of Munyo
36pub type Result<T> = std::result::Result<T, Error>;
37
38use std::path::Path;
39pub(crate) fn read_file<P: AsRef<Path>>(path: P) -> crate::Result<String> {
40    std::fs::read_to_string(&path)
41        .map_err(|e| crate::Error::ReadFile(path.as_ref().to_path_buf(), e.into()))
42}
43
44#[doc(hidden)]
45/// This is only meant for testing.
46///
47/// The created file survives until the NamedTempFile drops
48pub fn temp(s: &str) -> std::io::Result<tempfile::NamedTempFile> {
49    use std::io::{Seek, SeekFrom, Write};
50    let mut t = tempfile::NamedTempFile::new()?;
51    writeln!(t, "{s}")?;
52    t.seek(SeekFrom::Start(0))?;
53    Ok(t)
54}