pub struct JSONField {
pub name: String,
pub required: bool,
pub error_messages: HashMap<String, String>,
pub widget: Widget,
pub help_text: String,
pub initial: Option<Value>,
pub require_object: bool,
pub require_array: bool,
pub required_keys: Vec<String>,
pub max_depth: usize,
}Fields§
§name: String§required: bool§error_messages: HashMap<String, String>§widget: Widget§help_text: String§initial: Option<Value>§require_object: boolWhether to validate JSON is an object (not array, string, etc.)
require_array: boolWhether to validate JSON is an array
required_keys: Vec<String>Required keys for JSON objects
max_depth: usizeMaximum nesting depth for JSON deserialization to prevent stack overflow
Implementations§
Source§impl JSONField
impl JSONField
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new JSONField
§Examples
use reinhardt_forms::fields::JSONField;
let field = JSONField::new("config");
assert_eq!(field.name, "config");
assert!(field.required);pub fn required(self, required: bool) -> Self
pub fn help_text(self, text: impl Into<String>) -> Self
pub fn initial(self, value: Value) -> Self
pub fn require_object(self) -> Self
pub fn require_array(self) -> Self
pub fn required_keys(self, keys: Vec<String>) -> Self
Sourcepub fn max_depth(self, depth: usize) -> Self
pub fn max_depth(self, depth: usize) -> Self
Set the maximum nesting depth for JSON deserialization.
This prevents stack overflow attacks from deeply nested JSON payloads. Default is 64.
pub fn error_message( self, error_type: impl Into<String>, message: impl Into<String>, ) -> Self
Trait Implementations§
Source§impl FormField for JSONField
impl FormField for JSONField
fn name(&self) -> &str
fn label(&self) -> Option<&str>
fn widget(&self) -> &Widget
fn required(&self) -> bool
fn initial(&self) -> Option<&Value>
fn help_text(&self) -> Option<&str>
fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
Auto Trait Implementations§
impl Freeze for JSONField
impl RefUnwindSafe for JSONField
impl Send for JSONField
impl Sync for JSONField
impl Unpin for JSONField
impl UnsafeUnpin for JSONField
impl UnwindSafe for JSONField
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