Skip to content

Commit

Permalink
Vendor yaml (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Mar 26, 2024
1 parent d4cbd48 commit ece6fc9
Show file tree
Hide file tree
Showing 8 changed files with 4,354 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
similar = { version = "2.1.0", features = ["inline"] }
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
serde = { version = "1.0.117", optional = true }
linked-hash-map = "0.5.6"
lazy_static = "1.4.0"
Expand Down
12 changes: 6 additions & 6 deletions src/content/yaml.rs → src/content/yaml/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pub mod vendored;

use std::path::Path;

use crate::content::{Content, Error};

use yaml_rust::{yaml::Hash as YamlObj, Yaml as YamlValue};
use crate::content::yaml::vendored::{yaml::Hash as YamlObj, Yaml as YamlValue};

pub fn parse_str(s: &str, filename: &Path) -> Result<Content, Error> {
let mut blobs = yaml_rust::YamlLoader::load_from_str(s)
let mut blobs = crate::content::yaml::vendored::yaml::YamlLoader::load_from_str(s)
.map_err(|_| Error::FailedParsingYaml(filename.to_path_buf()))?;

match (blobs.pop(), blobs.pop()) {
Expand Down Expand Up @@ -38,17 +40,15 @@ fn from_yaml_blob(blob: YamlValue, filename: &Path) -> Result<Content, Error> {
.collect::<Result<_, Error>>()?;
Ok(Content::Map(obj))
}
YamlValue::BadValue | YamlValue::Alias(_) => {
Err(Error::FailedParsingYaml(filename.to_path_buf()))
}
YamlValue::BadValue => Err(Error::FailedParsingYaml(filename.to_path_buf())),
}
}

pub fn to_string(content: &Content) -> String {
let yaml_blob = to_yaml_value(content);

let mut buf = String::new();
let mut emitter = yaml_rust::YamlEmitter::new(&mut buf);
let mut emitter = crate::content::yaml::vendored::emitter::YamlEmitter::new(&mut buf);
emitter.dump(&yaml_blob).unwrap();

if !buf.ends_with('\n') {
Expand Down
Loading

0 comments on commit ece6fc9

Please sign in to comment.