Make (De)SerializeOptions as const

This commit is contained in:
Alex Orlenko 2021-11-04 01:07:38 +00:00
parent d88a4282c7
commit 0741db7565
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
2 changed files with 17 additions and 17 deletions

View File

@ -45,23 +45,23 @@ pub struct Options {
impl Default for Options { impl Default for Options {
fn default() -> Self { fn default() -> Self {
Options { Self::new()
deny_unsupported_types: true,
deny_recursive_tables: true,
}
} }
} }
impl Options { impl Options {
/// Returns a new instance of `Options` with default parameters. /// Returns a new instance of `Options` with default parameters.
pub fn new() -> Self { pub const fn new() -> Self {
Self::default() Options {
deny_unsupported_types: true,
deny_recursive_tables: true,
}
} }
/// Sets [`deny_unsupported_types`] option. /// Sets [`deny_unsupported_types`] option.
/// ///
/// [`deny_unsupported_types`]: #structfield.deny_unsupported_types /// [`deny_unsupported_types`]: #structfield.deny_unsupported_types
pub fn deny_unsupported_types(mut self, enabled: bool) -> Self { pub const fn deny_unsupported_types(mut self, enabled: bool) -> Self {
self.deny_unsupported_types = enabled; self.deny_unsupported_types = enabled;
self self
} }

View File

@ -52,24 +52,24 @@ pub struct Options {
impl Default for Options { impl Default for Options {
fn default() -> Self { fn default() -> Self {
Self::new()
}
}
impl Options {
/// Returns a new instance of [`Options`] with default parameters.
pub const fn new() -> Self {
Options { Options {
set_array_metatable: true, set_array_metatable: true,
serialize_none_to_null: true, serialize_none_to_null: true,
serialize_unit_to_null: true, serialize_unit_to_null: true,
} }
} }
}
impl Options {
/// Returns a new instance of [`Options`] with default parameters.
pub fn new() -> Self {
Self::default()
}
/// Sets [`set_array_metatable`] option. /// Sets [`set_array_metatable`] option.
/// ///
/// [`set_array_metatable`]: #structfield.set_array_metatable /// [`set_array_metatable`]: #structfield.set_array_metatable
pub fn set_array_metatable(mut self, enabled: bool) -> Self { pub const fn set_array_metatable(mut self, enabled: bool) -> Self {
self.set_array_metatable = enabled; self.set_array_metatable = enabled;
self self
} }
@ -77,7 +77,7 @@ impl Options {
/// Sets [`serialize_none_to_null`] option. /// Sets [`serialize_none_to_null`] option.
/// ///
/// [`serialize_none_to_null`]: #structfield.serialize_none_to_null /// [`serialize_none_to_null`]: #structfield.serialize_none_to_null
pub fn serialize_none_to_null(mut self, enabled: bool) -> Self { pub const fn serialize_none_to_null(mut self, enabled: bool) -> Self {
self.serialize_none_to_null = enabled; self.serialize_none_to_null = enabled;
self self
} }
@ -85,7 +85,7 @@ impl Options {
/// Sets [`serialize_unit_to_null`] option. /// Sets [`serialize_unit_to_null`] option.
/// ///
/// [`serialize_unit_to_null`]: #structfield.serialize_unit_to_null /// [`serialize_unit_to_null`]: #structfield.serialize_unit_to_null
pub fn serialize_unit_to_null(mut self, enabled: bool) -> Self { pub const fn serialize_unit_to_null(mut self, enabled: bool) -> Self {
self.serialize_unit_to_null = enabled; self.serialize_unit_to_null = enabled;
self self
} }