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

source

pub const fn all() -> Self

Enable all comment Styles

source

pub const fn hash_only() -> Self

Only allow line comments starting with #

source

pub const fn c_style() -> Self

Only allow “c-style” comments.

Specifically, line comments beginning with // and block comment like /* ... */.

source

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

source§

fn clone(&self) -> CommentSettings

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CommentSettings

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CommentSettings

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for CommentSettings

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.