Struct json_strip_comments::CommentSettings
source · pub struct CommentSettings { /* private fields */ }
Expand description
Settings for StripComments
The default is for all comment types to be enabled.
Implementations§
source§impl CommentSettings
impl CommentSettings
sourcepub const fn c_style() -> Self
pub const fn c_style() -> Self
Only allow “c-style” comments.
Specifically, line comments beginning with //
and
block comment like /* ... */
.
sourcepub fn strip_comments<I: Read>(self, input: I) -> StripComments<I> ⓘ
pub fn strip_comments<I: Read>(self, input: I) -> StripComments<I> ⓘ
Create a new StripComments
for input
, using these settings.
Transform input
into a Read
that strips out comments.
The types of comments to support are determined by the configuration of
self
.
§Examples
use json_strip_comments::CommentSettings;
use std::io::Read;
let input = r#"{
// c line comment
"a": "b"
/** multi line
comment
*/ }"#;
let mut stripped = String::new();
CommentSettings::c_style().strip_comments(input.as_bytes()).read_to_string(&mut stripped).unwrap();
assert_eq!(stripped, "{
\n\"a\": \"b\"
}");
use json_strip_comments::CommentSettings;
use std::io::Read;
let input = r#"{
# shell line comment
"a": "b"
}"#;
let mut stripped = String::new();
CommentSettings::hash_only().strip_comments(input.as_bytes()).read_to_string(&mut stripped).unwrap();
assert_eq!(stripped, "{
\n\"a\": \"b\"\n}");
Trait Implementations§
source§impl Clone for CommentSettings
impl Clone for CommentSettings
source§fn clone(&self) -> CommentSettings
fn clone(&self) -> CommentSettings
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for CommentSettings
impl Debug for CommentSettings
source§impl Default for CommentSettings
impl Default for CommentSettings
impl Copy for CommentSettings
Auto Trait Implementations§
impl Freeze for CommentSettings
impl RefUnwindSafe for CommentSettings
impl Send for CommentSettings
impl Sync for CommentSettings
impl Unpin for CommentSettings
impl UnwindSafe for CommentSettings
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)