Struct json_comments::CommentSettings
source · [−]pub struct CommentSettings { /* private fields */ }Expand description
Settings for StripComments
The default is for all comment types to be enabled.
Implementations
sourceimpl 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>ⓘNotable traits for StripComments<T>impl<T> Read for StripComments<T> where
T: Read,
pub fn strip_comments<I: Read>(self, input: I) -> StripComments<I>ⓘNotable traits for StripComments<T>impl<T> Read for StripComments<T> where
T: Read,
T: Read,
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_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_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
sourceimpl Clone for CommentSettings
impl Clone for CommentSettings
sourcefn clone(&self) -> CommentSettings
fn clone(&self) -> CommentSettings
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for CommentSettings
impl Debug for CommentSettings
sourceimpl Default for CommentSettings
impl Default for CommentSettings
impl Copy for CommentSettings
Auto Trait Implementations
impl RefUnwindSafe for CommentSettings
impl Send for CommentSettings
impl Sync for CommentSettings
impl Unpin for CommentSettings
impl UnwindSafe for CommentSettings
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more