Skip to main content

Field

Struct Field 

Source
pub struct Field {
Show 15 fields pub key: String, pub kind: FieldKind, pub label: String, pub hint: Option<String>, pub required: bool, pub default: Option<Value>, pub min: Option<i64>, pub max: Option<i64>, pub options: Vec<Choice>, pub format: TextFormat, pub multiline: bool, pub kinds: Vec<String>, pub entry_types: Vec<String>, pub tags: Vec<String>, pub multiple: Option<bool>,
}
Expand description

A field of a page. Its value comes back in the next call’s input under its key: a string for text and choice, a bool, an integer, for scenes a list of scene ids (one id or null when Field::single), and for entity an EntityRef or null (a list of them when Field::multiple). Hammer checks required, an int’s bounds, a choice’s options, and that an entity’s picks exist and match its filters before calling, unless the button pressed skips them.

Fields§

§key: String§kind: FieldKind§label: String§hint: Option<String>§required: bool

For text, not blank; for scenes, not empty; for entity, a pick.

§default: Option<Value>

The initial value; none for the kind’s own: false, min or 0, the first option, “”, or none.

§min: Option<i64>§max: Option<i64>§options: Vec<Choice>§format: TextFormat§multiline: bool§kinds: Vec<String>

An entity’s kinds of item: scene, note, entry, or event; all four when empty.

§entry_types: Vec<String>

An entity’s types of entry: person, place, thing, event, or idea; any when empty.

§tags: Vec<String>

An entity’s tags: an item needs one of them; any item when empty.

§multiple: Option<bool>

Whether the value is a list; none for the kind’s own, a list for scenes and one item for entity.

Implementations§

Source§

impl Field

Source

pub fn text(key: impl Into<String>, label: impl Into<String>) -> Field

A text field, plain unless given a Field::format.

Source

pub fn bool(key: impl Into<String>, label: impl Into<String>) -> Field

Source

pub fn int( key: impl Into<String>, label: impl Into<String>, min: Option<i64>, max: Option<i64>, ) -> Field

Source

pub fn choice( key: impl Into<String>, label: impl Into<String>, options: Vec<Choice>, ) -> Field

A choice of options, at least one.

Source

pub fn scenes(key: impl Into<String>, label: impl Into<String>) -> Field

Scenes picked from the project’s tree: a list, or one with Field::single.

Source

pub fn entity(key: impl Into<String>, label: impl Into<String>) -> Field

An item of the project picked by name: one EntityRef or null, or a list with Field::multiple. Field::kinds, Field::entry_types, and Field::tags narrow what the picker offers. Hammer shows a default that is gone or does not match as empty.

Source

pub fn hint(self, hint: impl Into<String>) -> Field

Source

pub fn required(self) -> Field

Source

pub fn default(self, value: impl Into<Value>) -> Field

The initial value, such as "elvish", 8, true, vec![3, 4], or an EntityRef (a Vec of them for an entity with Field::multiple).

Source

pub fn format(self, format: TextFormat) -> Field

Source

pub fn multiline(self) -> Field

A plain text field of several lines.

Source

pub fn single(self) -> Field

Scenes as one scene, or null, instead of a list.

Source

pub fn multiple(self) -> Field

An entity as a list of items instead of one.

Source

pub fn kinds(self, kinds: &[&str]) -> Field

The kinds of item an entity picks: scene, note, entry, or event.

Source

pub fn entry_types(self, types: &[&str]) -> Field

The types of entry an entity picks, with entry among its kinds: person, place, thing, event, or idea.

Source

pub fn tags(self, tags: &[&str]) -> Field

Tags an entity’s item needs one of.

Trait Implementations§

Source§

impl Clone for Field

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 Serialize for Field

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§

§

impl Forget for Field

§

impl Freeze for Field

§

impl Move for Field

§

impl RefUnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnsafeUnpin for Field

§

impl UnwindSafe for Field

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

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.