#[non_exhaustive]
pub struct ArrayField { pub label: String, pub name: String, pub minimum_length: u32, pub maximum_length: Option<u32>, pub element_schema: QuerySchema, }
Expand description

Defines an array of composite fields.

This is commonly used for arbitrarily long list of (key, value) pairs, or lists of (key, operator, value) filters.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§label: String

Suggested label to display along the form field.

§name: String

Name of the field as it will be included in the encoded query or config object.

§minimum_length: u32

The minimum number of entries the array must have to be valid.

Leaving the minimum_length to 0 makes the whole field optional.

§maximum_length: Option<u32>

The maximum number of entries the array can have and still be valid.

It is None when there is no maximum number

§element_schema: QuerySchema

The schema of the elements inside a row of the array.

§Accessing row fields

The name of each QueryField inside the element_schema can be used as an indexing key for a field. That means that if element_schema contains a TextField with the name parameter_name, then you will be able to access the value of that field using ArrayField::get(i)::get("parameter_name") for the i-th element.

§Serialization

For example if an array field has this element_schema:

ArrayField::new()
  .with_name("table")
  .with_label("example".to_string())
  .with_element_schema(vec![
    TextField::new().with_name("key").into(),
    SelectField::new().with_name("operator").with_options([
      "<".into(),
      ">".into(),
      "<=".into(),
      ">=".into(),
      "==".into()
    ]).into(),
    IntegerField::new().with_name("value").into(),
  ]);

Then the URL-encoded serialization for the fields is expected to use the bracketed-notation. This means you can encode all the keys in the array in any order you want. It can look like this (line breaks are only kept for legibility):

 "table[0][key]=less+than&
 table[2][operator]=%3E&
 table[0][operator]=%3C&
 table[2][key]=greater+than&
 table[2][value]=10&
 table[0][value]=12"

or you can do the “logic” ordering too:

 "table[0][key]=less+than&
 table[0][operator]=%3C&
 table[0][value]=12&
 table[1][key]=greater+than&
 table[1][operator]=%3E&
 table[1][value]=10"

Note that we are allowed to skip indices. Any of those 2 examples above will be read as:

assert_eq!(table, vec![
  Row {
    key: "less than".to_string(),
    operator: "<".to_string(),
    value: 12,
  },
  Row {
    key: "greater than".to_string(),
    operator: ">".to_string(),
    value: 10,
  },
]);
§Required row fields

Any field that is marked as required inside element_schema makes it mandatory to create a valid row to the Array Field.

Implementations§

source§

impl ArrayField

source

pub fn new() -> Self

Creates a new array field with all default values.

source

pub fn with_label(self, label: impl Into<String>) -> Self

source

pub fn with_element_schema(self, schema: QuerySchema) -> Self

source

pub fn with_name(self, name: impl Into<String>) -> Self

source

pub fn with_minimum_length(self, minimum_length: u32) -> Self

source

pub fn with_maximum_length(self, maximum_length: u32) -> Self

Trait Implementations§

source§

impl Clone for ArrayField

source§

fn clone(&self) -> ArrayField

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 ArrayField

source§

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

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

impl Default for ArrayField

source§

fn default() -> ArrayField

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

impl<'de> Deserialize<'de> for ArrayField

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<ArrayField> for QueryField

source§

fn from(field: ArrayField) -> Self

Converts to this type from the input type.
source§

impl PartialEq for ArrayField

source§

fn eq(&self, other: &ArrayField) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for ArrayField

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for ArrayField

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> 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.
source§

impl<T> BindgenSerializable for T

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,