Skip to content

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ppca committed Feb 1, 2023
1 parent 9821a26 commit 693e452
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub struct Genesis {

impl GenesisConfig {
/// Parses GenesisConfig from a JSON string.
///
/// The string can be a JSON with comments.
/// It panics if the contents cannot be parsed from JSON to the GenesisConfig structure.
pub fn from_json(value: &str) -> Self {
let json_str_without_comments: String =
Expand All @@ -269,7 +269,7 @@ impl GenesisConfig {
}

/// Reads GenesisConfig from a JSON file.
///
/// The file can be a JSON with comments.
/// It panics if file cannot be open or read, or the contents cannot be parsed from JSON to the
/// GenesisConfig structure.
pub fn from_file<P: AsRef<Path>>(path: P) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -316,7 +316,7 @@ impl GenesisRecords {
}

/// Reads GenesisRecords from a JSON file.
///
/// The file can be a JSON with comments.
/// It panics if file cannot be open or read, or the contents cannot be parsed from JSON to the
/// GenesisConfig structure.
pub fn from_file<P: AsRef<Path>>(path: P) -> Self {
Expand Down Expand Up @@ -408,6 +408,7 @@ impl<'de, F: FnMut(StateRecord)> DeserializeSeed<'de> for RecordsProcessor<&'_ m
}
}

/// The file can be a JSON with comments
pub fn stream_records_from_file(
reader: impl Read,
mut callback: impl FnMut(StateRecord),
Expand Down
5 changes: 5 additions & 0 deletions utils/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ use std::io::Read;

use json_comments::StripComments;

// strip comments from a JSON string with comments.
// the comment formats that are supported: //, /* */ and #.
// json-comments-rs is used
// check out more details: https://github.com/tmccombs/json-comments-rs/blob/main/src/lib.rs
pub fn strip_comments_from_json_str(json_str: &String) -> std::io::Result<String> {
let mut content_without_comments = String::new();
StripComments::new(json_str.as_bytes()).read_to_string(&mut content_without_comments)?;
Ok(content_without_comments)
}

// strip comments from a JSON input with comments.
pub fn strip_comments_from_json_reader(reader: impl Read) -> impl Read {
StripComments::new(reader)
}

0 comments on commit 693e452

Please sign in to comment.