Skip to main content

CommandDef

Struct CommandDef 

Source
pub struct CommandDef<M: Model> { /* private fields */ }
Expand description

A builder for defining a command of a device.

Implementations§

Source§

impl<M: Model> CommandDef<M>

Source

pub fn new<N>(name: N) -> Self
where N: Into<Cow<'static, str>>,

Create a new command definition, without any execution function.

Source

pub fn in_doc<D>(self, doc: D) -> Self
where D: Into<Cow<'static, str>>,

Set the documentation of the command argument (argin).

A command has no description of its own, Tango only telling a client what each side of it is, so what the command does has to be said in one of these two.

Source

pub fn out_doc<D>(self, doc: D) -> Self
where D: Into<Cow<'static, str>>,

Set the documentation of the command result (argout).

Source

pub fn display_level(self, level: DisplayLevel) -> Self

Set the display level of the command, DisplayLevel::Expert keeping it out of the panels an operator is shown without keeping it from anyone who asks for it.

Source

pub fn polled(self, period: Duration) -> Self

Ask for the command to be polled at that period, its result being kept in the polling buffer of the device the way a polled attribute value is, which is what State and Status are usually given.

Only a command that takes no argument can be polled, there being no argument for the server to invent, and the database has the last word on the period.

Source

pub fn in_kind(self, kind: CommandDataKind) -> Self

Set the advertised kind of the command argument (argin). This is only needed for the execution functions that take a raw Value argument, the typed ones derive it from their input type.

§Panics

If the argument kind has already been defined, explicitly or by an execution function, as a different kind.

Source

pub fn out_kind(self, kind: CommandDataKind) -> Self

Set the advertised kind of the command result (argout). This is only needed for the execution functions that return a raw Value, the typed ones derive it from their output type.

§Panics

If the result kind has already been defined, explicitly or by an execution function, as a different kind.

Source

pub fn exec_with<F>(self, func: F) -> Self
where F: Fn(&M, &Dev<M>, Value) -> Result<Value> + Send + Sync + 'static,

Define the execution function of this command, with a shared access to the model.

This is the raw form of Self::exec: the closure is given the argument Value as-is and returns one, converting what it borrows from the model itself, which is what makes a closure usable for such a result. Because no input and output types are involved, the advertised kinds have to be given with Self::in_kind and Self::out_kind.

Source

pub fn exec<F, I>(self, func: F) -> Self
where F: for<'m> ExecShared<'m, M, I> + Send + Sync + 'static,

Define the execution function of this command, with a shared access to the model, which allows parallel execution of such functions.

The argument and result types are taken from the ExecShared implementation of the function. The result may borrow from the model, being converted into a value before the model is released, which requires a function item generic over the model lifetime, typically an associated method of the model.

§Panics

If either advertised kind has already been defined as a different kind, see Self::in_kind and Self::out_kind.

Source

pub fn exec_exclusive_with<F>(self, func: F) -> Self
where F: Fn(&mut M, &Dev<M>, Value) -> Result<Value> + Send + Sync + 'static,

Define the execution function of this command, with an exclusive access to the model. This is the raw form of Self::exec_exclusive, see Self::exec_with.

Source

pub fn exec_exclusive<F, I>(self, func: F) -> Self
where F: for<'m> ExecExclusive<'m, M, I> + Send + Sync + 'static,

Define the execution function of this command, with an exclusive access to the model, therefore no other command or attribute can access it in parallel.

See Self::exec for the constraints on the argument and result types, this one is only different in that its function item takes the model by exclusive reference.

§Panics

If either advertised kind has already been defined as a different kind, see Self::in_kind and Self::out_kind.

Source

pub fn exec_async_with<F>(self, func: F) -> Self
where F: for<'a> Fn(&'a M, &'a Dev<M>, Value) -> BoxFuture<'a, Result<Value>> + Send + Sync + 'static,

Define the execution function of this command, asynchronously and with a shared access to the model. This is the raw form of Self::exec_async, for a closure that boxes its future itself, see Self::exec_with.

Source

pub fn exec_async<F, I>(self, func: F) -> Self
where F: for<'a> ExecAsync<'a, &'a M, M, I> + Send + Sync + 'static,

Define the execution function of this command, asynchronously and with a shared access to the model, typically an async fn method of the model.

This is what a command forwarding its execution to other devices is written as: it holds no thread while it waits on them, and may wait on many of them at once. The future is polled by the server itself, so it must never block, see ClassDef::state_async.

§Panics

If either advertised kind has already been defined as a different kind, see Self::in_kind and Self::out_kind.

Source

pub fn exec_exclusive_async_with<F>(self, func: F) -> Self
where F: for<'a> Fn(&'a mut M, &'a Dev<M>, Value) -> BoxFuture<'a, Result<Value>> + Send + Sync + 'static,

Define the execution function of this command, asynchronously and with an exclusive access to the model. This is the raw form of Self::exec_exclusive_async, see Self::exec_async_with.

Source

pub fn exec_exclusive_async<F, I>(self, func: F) -> Self
where F: for<'a> ExecAsync<'a, &'a mut M, M, I> + Send + Sync + 'static,

Define the execution function of this command, asynchronously and with an exclusive access to the model, which no other command or attribute can then access until the future completes. See Self::exec_async.

§Panics

If either advertised kind has already been defined as a different kind, see Self::in_kind and Self::out_kind.

Trait Implementations§

Source§

impl<M: Model> Debug for CommandDef<M>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for CommandDef<M>

§

impl<M> !UnwindSafe for CommandDef<M>

§

impl<M> Freeze for CommandDef<M>
where Option<ExecFn<M>>: Freeze,

§

impl<M> Send for CommandDef<M>
where Option<ExecFn<M>>: Send,

§

impl<M> Sync for CommandDef<M>
where Option<ExecFn<M>>: Sync,

§

impl<M> Unpin for CommandDef<M>
where Option<ExecFn<M>>: Unpin,

§

impl<M> UnsafeUnpin for CommandDef<M>
where Option<ExecFn<M>>: UnsafeUnpin,

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> 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> Model for T
where T: Send + Sync + 'static,

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