From 77a7f5d8da58eca20e7218c2d3d18135e84d883e Mon Sep 17 00:00:00 2001 From: Xiangyi Zheng Date: Wed, 1 Feb 2023 07:14:44 -0800 Subject: [PATCH] more comments --- core/chain-configs/src/genesis_config.rs | 7 ++++--- utils/config/src/lib.rs | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index 6aea33ad19d..e03e4daab05 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -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 = @@ -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>(path: P) -> anyhow::Result { @@ -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>(path: P) -> Self { @@ -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), diff --git a/utils/config/src/lib.rs b/utils/config/src/lib.rs index 8bdac440614..2de28c90418 100644 --- a/utils/config/src/lib.rs +++ b/utils/config/src/lib.rs @@ -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 { 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) }