pub enum BlockField {
Widget {
name: String,
label: String,
widget: WidgetKind,
options: Vec<(String, String)>,
help: Option<String>,
required: bool,
meta: BlockFieldMeta,
},
Computed {
name: String,
label: String,
render: fn(&Value, &BlockRenderCtx<'_>) -> String,
help: Option<String>,
},
Stream {
name: String,
label: String,
allowed: Vec<String>,
min: Option<u32>,
max: Option<u32>,
block_counts: HashMap<String, BlockCountConstraint>,
},
Repeat {
name: String,
label: String,
item_type: String,
min: Option<u32>,
max: Option<u32>,
},
}Expand description
One declared field inside a block’s structural shape. The four variants together cover struct, stream, list and static blocks — a single recursive enum, walked once, validated once, rendered once.
Variants§
Widget
A scalar leaf. Pairs a name with one
rcms WidgetKind for the admin editor; the JSON value is
whatever shape that widget POSTs.
Fields
widget: WidgetKindoptions: Vec<(String, String)>Choice-widget (value, label) pairs. Empty for non-choice
kinds. Matches the existing crate::widget::Widget::options
shape.
meta: BlockFieldMetaHTML5 / value validators (min_length, max_length,
pattern, min_value, max_value, default_value).
Default = no constraints; threaded into the rendered
Widget at editor render time.
Computed
A read-only computed leaf — pure function of the block value.
Renders inline in the admin editor + on the public page. No
JSON column, no form input. Same idea as the
DisplayField shape.
Fields
render: fn(&Value, &BlockRenderCtx<'_>) -> StringPure function of the block’s value. The default render
passes the whole block value (the {name1: val1, …}
dict) so computed fields can derive from siblings.
Function pointer (not Box<dyn Fn>) so the variant stays
Clone-able cheaply and inventory-friendly.
Stream
Heterogeneous nested list. allowed
lists which registered block types may appear here. Boot-time
validation in validate_block_registry verifies every entry
resolves.
Fields
block_counts: HashMap<String, BlockCountConstraint>Block counts — per-block-type cardinality
(e.g. {"heading": BlockCountConstraint { min: Some(1), max: Some(3) }}). Independent of the stream-wide
min / max. Empty map = no per-type constraints.
Repeat
Homogeneous nested list. Convenience
shorthand for Stream { allowed: &[item_type] } with the
admin editor showing a single “+ Add” button (no picker — only
one type is permitted).
Implementations§
Source§impl BlockField
impl BlockField
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The wire-format name used as the dict key inside a block’s
value object.
Sourcepub fn widget(
name: impl Into<String>,
label: impl Into<String>,
widget: WidgetKind,
) -> Self
pub fn widget( name: impl Into<String>, label: impl Into<String>, widget: WidgetKind, ) -> Self
Fluent constructor for a single-widget field.
Sourcepub fn stream<S: Into<String>>(
name: impl Into<String>,
label: impl Into<String>,
allowed: impl IntoIterator<Item = S>,
) -> Self
pub fn stream<S: Into<String>>( name: impl Into<String>, label: impl Into<String>, allowed: impl IntoIterator<Item = S>, ) -> Self
Fluent constructor for a stream field.
Sourcepub fn repeat(
name: impl Into<String>,
label: impl Into<String>,
item_type: impl Into<String>,
) -> Self
pub fn repeat( name: impl Into<String>, label: impl Into<String>, item_type: impl Into<String>, ) -> Self
Fluent constructor for a repeat (single-type list) field.
Sourcepub fn with_meta(self, meta: BlockFieldMeta) -> Self
pub fn with_meta(self, meta: BlockFieldMeta) -> Self
Attach a validator pack (BlockFieldMeta) to a Widget
variant. No-op on the other variants. Built so authors can
chain: BlockField::widget(...).with_meta(meta).
Sourcepub fn with_block_counts(
self,
counts: HashMap<String, BlockCountConstraint>,
) -> Self
pub fn with_block_counts( self, counts: HashMap<String, BlockCountConstraint>, ) -> Self
Attach a per-block-type cardinality map to a Stream variant. No-op on other variants.
Sourcepub fn with_help(self, h: impl Into<String>) -> Self
pub fn with_help(self, h: impl Into<String>) -> Self
Set helptext on a Widget field (no-op on other variants).
Sourcepub fn with_options<K, V, I>(self, opts: I) -> Self
pub fn with_options<K, V, I>(self, opts: I) -> Self
Replace the choice-options on a Widget field
(no-op on other variants). Pairs are (value, label).
Sourcepub fn with_min(self, n: u32) -> Self
pub fn with_min(self, n: u32) -> Self
Set min cardinality on Stream / Repeat fields (no-op on Widget / Computed). Cardinality below this is a validation error.
Sourcepub fn with_max(self, n: u32) -> Self
pub fn with_max(self, n: u32) -> Self
Set max cardinality on Stream / Repeat fields (no-op on Widget / Computed). Cardinality above this is a validation error.
Sourcepub fn markdown(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn markdown(name: impl Into<String>, label: impl Into<String>) -> Self
Markdown-source editor with the bundled toolbar.
Sourcepub fn richtext(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn richtext(name: impl Into<String>, label: impl Into<String>) -> Self
HTML rich-text editor.
Sourcepub fn int(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn int(name: impl Into<String>, label: impl Into<String>) -> Self
<input type="number" step="1">.
Sourcepub fn float(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn float(name: impl Into<String>, label: impl Into<String>) -> Self
<input type="number" step="any"> (free-form decimal).
Sourcepub fn boolean(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn boolean(name: impl Into<String>, label: impl Into<String>) -> Self
<input type="checkbox">.
Sourcepub fn datetime(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn datetime(name: impl Into<String>, label: impl Into<String>) -> Self
<input type="datetime-local">.
Sourcepub fn choice<K, V, I>(
name: impl Into<String>,
label: impl Into<String>,
choices: I,
) -> Self
pub fn choice<K, V, I>( name: impl Into<String>, label: impl Into<String>, choices: I, ) -> Self
<select> dropdown with the given (value, label) choices.
Convenience around Self::widget + Self::with_options.
Sourcepub fn media(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn media(name: impl Into<String>, label: impl Into<String>) -> Self
MediaPicker — pick an existing cms_media row.
Sourcepub fn page(name: impl Into<String>, label: impl Into<String>) -> Self
pub fn page(name: impl Into<String>, label: impl Into<String>) -> Self
PageChooser — pick a cms_page row via modal.
Trait Implementations§
Source§impl Clone for BlockField
impl Clone for BlockField
Source§impl Debug for BlockField
impl Debug for BlockField
Auto Trait Implementations§
impl Freeze for BlockField
impl RefUnwindSafe for BlockField
impl Send for BlockField
impl Sync for BlockField
impl Unpin for BlockField
impl UnsafeUnpin for BlockField
impl UnwindSafe for BlockField
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more