Skip to main content

BlockField

Enum BlockField 

Source
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

§name: String
§label: String
§widget: WidgetKind
§options: Vec<(String, String)>

Choice-widget (value, label) pairs. Empty for non-choice kinds. Matches the existing crate::widget::Widget::options shape.

§required: bool
§meta: BlockFieldMeta

HTML5 / 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

§name: String
§label: String
§render: fn(&Value, &BlockRenderCtx<'_>) -> String

Pure 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

§name: String
§label: String
§allowed: Vec<String>
§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).

Fields

§name: String
§label: String
§item_type: String

Implementations§

Source§

impl BlockField

Source

pub fn name(&self) -> &str

The wire-format name used as the dict key inside a block’s value object.

Source

pub fn widget( name: impl Into<String>, label: impl Into<String>, widget: WidgetKind, ) -> Self

Fluent constructor for a single-widget field.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn required(self) -> Self

Mark a Widget field required (no-op on other variants).

Source

pub fn with_help(self, h: impl Into<String>) -> Self

Set helptext on a Widget field (no-op on other variants).

Source

pub fn with_options<K, V, I>(self, opts: I) -> Self
where K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>,

Replace the choice-options on a Widget field (no-op on other variants). Pairs are (value, label).

Source

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.

Source

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.

Source

pub fn char(name: impl Into<String>, label: impl Into<String>) -> Self

Single-line text input.

Source

pub fn text(name: impl Into<String>, label: impl Into<String>) -> Self

Multi-line text input.

Source

pub fn markdown(name: impl Into<String>, label: impl Into<String>) -> Self

Markdown-source editor with the bundled toolbar.

Source

pub fn richtext(name: impl Into<String>, label: impl Into<String>) -> Self

HTML rich-text editor.

Source

pub fn email(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="email">.

Source

pub fn url(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="url">.

Source

pub fn int(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="number" step="1">.

Source

pub fn float(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="number" step="any"> (free-form decimal).

Source

pub fn boolean(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="checkbox">.

Source

pub fn date(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="date">.

Source

pub fn datetime(name: impl Into<String>, label: impl Into<String>) -> Self

<input type="datetime-local">.

Source

pub fn choice<K, V, I>( name: impl Into<String>, label: impl Into<String>, choices: I, ) -> Self
where K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>,

<select> dropdown with the given (value, label) choices. Convenience around Self::widget + Self::with_options.

Source

pub fn media(name: impl Into<String>, label: impl Into<String>) -> Self

MediaPicker — pick an existing cms_media row.

Source

pub fn page(name: impl Into<String>, label: impl Into<String>) -> Self

PageChooser — pick a cms_page row via modal.

Source

pub fn snippet(name: impl Into<String>, label: impl Into<String>) -> Self

SnippetChooser — pick a cms_snippet row via modal.

Source

pub fn document(name: impl Into<String>, label: impl Into<String>) -> Self

DocumentChooser — pick a non-image cms_media row via modal.

Trait Implementations§

Source§

impl Clone for BlockField

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockField

Source§

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

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

impl Serialize for BlockField

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more