pub struct BoundField<'a> { /* private fields */ }Available on crate feature
forms and non-WebAssembly only.Expand description
BoundField represents a field bound to form data
Implementations§
Source§impl<'a> BoundField<'a>
impl<'a> BoundField<'a>
Sourcepub fn new(
form_name: String,
field: &'a dyn FormField,
data: Option<&'a Value>,
errors: &'a [String],
prefix: &'a str,
) -> BoundField<'a>
pub fn new( form_name: String, field: &'a dyn FormField, data: Option<&'a Value>, errors: &'a [String], prefix: &'a str, ) -> BoundField<'a>
Documentation for new
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("name".to_string()));
let data = serde_json::json!("John");
let errors = vec![];
let bound = BoundField::new("my_form".to_string(), field.as_ref(), Some(&data), &errors, "");
assert_eq!(bound.name(), "name");
assert_eq!(bound.value(), Some(&data));Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Get the field name
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("email".to_string()));
let bound = BoundField::new("form".to_string(), field.as_ref(), None, &[], "");
assert_eq!(bound.name(), "email");Sourcepub fn html_name(&self) -> String
pub fn html_name(&self) -> String
Get the HTML name attribute (with prefix)
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("email".to_string()));
// Without prefix
let bound = BoundField::new("form".to_string(), field.as_ref(), None, &[], "");
assert_eq!(bound.html_name(), "email");
// With prefix
let bound_prefixed = BoundField::new("form".to_string(), field.as_ref(), None, &[], "user");
assert_eq!(bound_prefixed.html_name(), "user-email");Sourcepub fn id_for_label(&self) -> String
pub fn id_for_label(&self) -> String
Get the HTML id attribute
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("username".to_string()));
let bound = BoundField::new("form".to_string(), field.as_ref(), None, &[], "profile");
assert_eq!(bound.id_for_label(), "id_profile-username");Sourcepub fn label(&self) -> Option<&str>
pub fn label(&self) -> Option<&str>
Get the field label
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let mut field = CharField::new("name".to_string());
field.label = Some("Full Name".to_string());
let field_box: Box<dyn FormField> = Box::new(field);
let bound = BoundField::new("form".to_string(), field_box.as_ref(), None, &[], "");
assert_eq!(bound.label(), Some("Full Name"));Sourcepub fn value(&self) -> Option<&Value>
pub fn value(&self) -> Option<&Value>
Get the field value
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("name".to_string()));
let data = serde_json::json!("Alice");
let bound = BoundField::new("form".to_string(), field.as_ref(), Some(&data), &[], "");
assert_eq!(bound.value(), Some(&data));Sourcepub fn errors(&self) -> &[String]
pub fn errors(&self) -> &[String]
Get field errors
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("email".to_string()));
let errors = vec!["Invalid email format".to_string(), "Email is required".to_string()];
let bound = BoundField::new("form".to_string(), field.as_ref(), None, &errors, "");
assert_eq!(bound.errors().len(), 2);
assert_eq!(bound.errors()[0], "Invalid email format");Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Check if field has errors
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let field: Box<dyn FormField> = Box::new(CharField::new("username".to_string()));
// Without errors
let bound_ok = BoundField::new("form".to_string(), field.as_ref(), None, &[], "");
assert!(!bound_ok.has_errors());
// With errors
let errors = vec!["Username is required".to_string()];
let bound_err = BoundField::new("form".to_string(), field.as_ref(), None, &errors, "");
assert!(bound_err.has_errors());Sourcepub fn widget(&self) -> &Widget
pub fn widget(&self) -> &Widget
Get the widget
§Examples
use reinhardt_forms::{BoundField, CharField, EmailField, FormField, Widget};
let field: Box<dyn FormField> = Box::new(CharField::new("name".to_string()));
let bound = BoundField::new("form".to_string(), field.as_ref(), None, &[], "");
assert!(matches!(bound.widget(), Widget::TextInput));
let email_field: Box<dyn FormField> = Box::new(EmailField::new("email".to_string()));
let email_bound = BoundField::new("form".to_string(), email_field.as_ref(), None, &[], "");
assert!(matches!(email_bound.widget(), Widget::EmailInput));Sourcepub fn help_text(&self) -> Option<&str>
pub fn help_text(&self) -> Option<&str>
Get help text
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let mut field = CharField::new("password".to_string());
field.help_text = Some("Must be at least 8 characters".to_string());
let field_box: Box<dyn FormField> = Box::new(field);
let bound = BoundField::new("form".to_string(), field_box.as_ref(), None, &[], "");
assert_eq!(bound.help_text(), Some("Must be at least 8 characters"));Sourcepub fn is_required(&self) -> bool
pub fn is_required(&self) -> bool
Check if field is required
§Examples
use reinhardt_forms::{BoundField, CharField, FormField};
let mut field = CharField::new("name".to_string());
field.required = true;
let field_box: Box<dyn FormField> = Box::new(field);
let bound = BoundField::new("form".to_string(), field_box.as_ref(), None, &[], "");
assert!(bound.is_required());
let mut optional_field = CharField::new("nickname".to_string());
optional_field.required = false;
let optional_box: Box<dyn FormField> = Box::new(optional_field);
let optional_bound = BoundField::new("form".to_string(), optional_box.as_ref(), None, &[], "");
assert!(!optional_bound.is_required());Auto Trait Implementations§
impl<'a> Freeze for BoundField<'a>
impl<'a> !RefUnwindSafe for BoundField<'a>
impl<'a> Send for BoundField<'a>
impl<'a> Sync for BoundField<'a>
impl<'a> Unpin for BoundField<'a>
impl<'a> UnsafeUnpin for BoundField<'a>
impl<'a> !UnwindSafe for BoundField<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Creates a shared type from an unshared type.
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.