Skip to main content

Descriptor

Struct Descriptor 

Source
#[non_exhaustive]
pub struct Descriptor {
Show 19 fields pub ty: Type, pub label: String, pub description: String, pub default: Value, pub hard: Option<(f64, f64)>, pub soft: Option<(f64, f64)>, pub step: f64, pub coarse: f64, pub unit: Option<String>, pub display_scale: f64, pub precision: u32, pub choices: Vec<String>, pub count: Option<u32>, pub capacity: Option<u32>, pub path: Option<PathHint>, pub writers: Writers, pub sensitive: bool, pub scopes: Vec<ValueScope>, pub note: bool,
}
Expand description

What a value is and how it is shown and moved.

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.
§ty: Type§label: String§description: String§default: Value§hard: Option<(f64, f64)>

What the value can be, at most.

§soft: Option<(f64, f64)>

What a slider spans; past it up to hard only when forced.

§step: f64§coarse: f64§unit: Option<String>§display_scale: f64

Shown value = value × scale.

§precision: u32

Decimals shown.

§choices: Vec<String>§count: Option<u32>

How many values a list holds at most.

§capacity: Option<u32>

How many bytes a text holds at most.

§path: Option<PathHint>

A text that names a path on disk.

§writers: Writers

Who may write it besides its owner.

§sensitive: bool

A secret (a token, a password): never written to a settings export, never read from one.

§scopes: Vec<ValueScope>

The host’s value scopes it may also be set for, above app (opt-in, crate::admin::ValueScope); empty: app-wide only.

Experimental: may change in any release (docs/stability.md).
§note: bool

Not a value but a read-only line, its words the label (Descriptor::note): a dialog’s form shows it under the fields before it and answers no value for it.

Implementations§

Source§

impl Descriptor

Source

pub fn note(text: &str) -> Self

A read-only line of a form, what the command will also do (“Also updates 2 templates”): the forms’ counterpart of the admin forms’ note field kind.

Source

pub fn float(label: &str, min: f64, max: f64, default: f64) -> Self

A float in [min, max], its fine step a hundredth of the range.

Source

pub fn int(label: &str, min: i64, max: i64, default: i64) -> Self

Source

pub fn bool(label: &str, default: bool) -> Self

Source

pub fn choice(label: &str, choices: &[&str], default: &str) -> Self

Source

pub fn text(label: &str, default: &str) -> Self

Source

pub fn floats( label: &str, count: u32, min: f64, max: f64, default: &[f64], ) -> Self

Floats in [min, max], at most count of them.

Source

pub fn ints( label: &str, count: u32, min: i64, max: i64, default: &[i64], ) -> Self

Ints in [min, max], at most count of them.

Source

pub fn path(label: &str, kind: PathKind, extensions: &[&str]) -> Self

A text naming a directory or a file, empty by default; for a file, the extensions accepted (none: any).

Source

pub fn dialog_title(self, title: &str) -> Self

A path’s chooser title, a task (“Open a workspace”) rather than the field’s label; nothing for a value that names no path.

Source

pub fn dialog_purpose(self, key: &str) -> Self

The key a path’s chooser remembers its last folder under (default: the form’s command and the field’s key); nothing for a value that names no path.

Source

pub fn filter_name(self, name: &str) -> Self

What a path’s chooser calls its extensions’ filter (“Enrolment files”); nothing for a value that names no path.

Source

pub fn description(self, text: &str) -> Self

Source

pub fn soft(self, lo: f64, hi: f64) -> Self

The range a slider spans, within the hard range.

Source

pub fn step(self, step: f64) -> Self

The fine step (the coarse one becomes ten of them).

Source

pub fn coarse(self, coarse: f64) -> Self

Source

pub fn unit(self, unit: &str) -> Self

Source

pub fn display(self, scale: f64, precision: u32) -> Self

Shown value = value × scale, with so many decimals.

Source

pub fn capacity(self, bytes: u32) -> Self

At most so many bytes of text.

Source

pub fn writers(self, writers: &[OwnerId]) -> Self

Lets these write it too, besides its owner (one writer per value otherwise).

Source

pub fn any_writer(self) -> Self

Lets anyone write it.

Source

pub fn scopes(self, scopes: &[ValueScope]) -> Self

Opts into host value scopes: the settings app offers “Set for” with app and these (those the host has open).

Experimental: may change in any release (docs/stability.md).
Source

pub fn sensitive(self) -> Self

A secret: left out of settings exports and refused from them.

Source

pub fn accept(&self, json: &Json) -> Result<Value, String>

Checks a value read from outside (an imported file) against what the value can be: its type, its hard range (refused, never clamped), its choices, its count and its capacity. The value as the store holds it, or why not.

Trait Implementations§

Source§

impl Clone for Descriptor

Source§

fn clone(&self) -> Descriptor

Returns a duplicate 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 Descriptor

Source§

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

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

impl PartialEq for Descriptor

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Descriptor

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 Descriptor

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

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.