Skip to main content

ClassDef

Struct ClassDef 

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

A builder for defining a device model and interface.

Implementations§

Source§

impl<M: Model> ClassDef<M>

Source

pub fn new<N, I>(name: N, init: I) -> Self
where N: Into<Cow<'static, str>>, I: for<'ctx> Fn(&'ctx Dev<M>) -> Result<M> + Send + Sync + 'static,

Create a new class definition, the given function building the model of each device of that class when it is initialized.

Source

pub fn new_async_with<N, I>(name: N, init: I) -> Self
where N: Into<Cow<'static, str>>, I: for<'a> Fn(&'a Dev<M>) -> BoxFuture<'a, Result<M>> + Send + Sync + 'static,

Create a new class definition, the given function building the model of each device of that class asynchronously when it is initialized. This is the raw form of Self::new_async, for a closure that boxes its future itself.

Source

pub fn new_async<N, I>(name: N, init: I) -> Self
where N: Into<Cow<'static, str>>, I: for<'a> InitAsync<'a, M> + Send + Sync + 'static,

Create a new class definition, the given function building the model of each device of that class asynchronously when it is initialized, typically an async fn taking the device.

The model of the device is locked exclusively until the future completes, as it is for a synchronous one. The future is polled by the server itself when nothing else of the initialization may block, so it must never block, see Self::state_async.

Source

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

Create a new class definition whose model is built with its default value.

Source

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

Set the description the devices of that class give of themselves, which is what a client asking a device what it is gets back, and what a class defines once for all of its devices.

Source

pub fn doc_url<U>(self, url: U) -> Self
where U: Into<Cow<'static, str>>,

Set where the documentation of that class is, which is what a client shows as the documentation of every device of it: a page describing what the class does, not what one device of it is doing, which is its status.

Source

pub fn delete<F>(self, delete: F) -> Self
where F: for<'ctx> Fn(M, &'ctx Dev<M>) + Send + Sync + 'static,

Define the function called when the model of a device of that class is deleted, which is given the model back so that it may release its resources: before every initialization but the first, which is what the Init command of a device is, and once the device is no longer served. This is the one place a model releases its resources, its Drop being only relied upon to free memory, see Model.

Source

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

Define the function called when the model of a device of that class is deleted, asynchronously. This is the raw form of Self::delete_async, for a closure that boxes its future itself.

Source

pub fn delete_async<F>(self, delete: F) -> Self
where F: for<'a> DeleteAsync<'a, M> + Send + Sync + 'static,

Define the function called when the model of a device of that class is deleted, asynchronously, typically an async fn taking the model and the device, see Self::delete.

The model of the device is locked exclusively until the future completes, as it is for a synchronous one. The future is polled by the server itself when nothing else of the deletion may block, so it must never block, see Self::state_async.

Source

pub fn state<F>(self, state: F) -> Self
where F: for<'m, 'ctx> Fn(&'m M, &'ctx Dev<M>) -> Result<DevState> + Send + Sync + 'static,

Define the function giving the state of the device, with a shared access to the model, which allows parallel execution of such functions.

Source

pub fn state_exclusive<F>(self, state: F) -> Self
where F: for<'m, 'ctx> Fn(&'m mut M, &'ctx Dev<M>) -> Result<DevState> + Send + Sync + 'static,

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

Source

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

Define the function giving the state of the device, asynchronously and with a shared access to the model. This is the raw form of Self::state_async, for a closure that boxes its future itself.

Source

pub fn state_async<F>(self, state: F) -> Self
where F: for<'a> HandlerAsync<'a, &'a M, M, DevState> + Send + Sync + 'static,

Define the function giving the state of the device, asynchronously and with a shared access to the model, typically an async fn method of the model.

The model stays borrowed until the future completes, and the future is polled by the server itself, so it must never block: a function that has to wait on anything else than another future offloads that wait to a thread of its own.

Source

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

Define the function giving the state of the device, asynchronously and with an exclusive access to the model. This is the raw form of Self::state_exclusive_async, see Self::state_async_with.

Source

pub fn state_exclusive_async<F>(self, state: F) -> Self
where F: for<'a> HandlerAsync<'a, &'a mut M, M, DevState> + Send + Sync + 'static,

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

Source

pub fn status_with<F>(self, status: F) -> Self
where F: for<'m, 'ctx> Fn(&'m M, &'ctx Dev<M>) -> Result<Scalar<str>> + Send + Sync + 'static,

Define the function giving the status of the device, with a shared access to the model. This is the raw form of Self::status, for a closure that gives a Scalar itself.

Source

pub fn status<F>(self, status: F) -> Self
where F: for<'m> StatusSync<&'m M, M> + Send + Sync + 'static,

Define the function giving the status of the device, with a shared access to the model.

The status is anything that converts into a Scalar, and may borrow from the model: it is then written as a function item generic over the model lifetime, typically an associated method of the model, which StatusSync describes.

Source

pub fn status_exclusive_with<F>(self, status: F) -> Self
where F: for<'m, 'ctx> Fn(&'m mut M, &'ctx Dev<M>) -> Result<Scalar<str>> + Send + Sync + 'static,

Define the function giving the status of the device, with an exclusive access to the model. This is the raw form of Self::status_exclusive, see Self::status_with.

Source

pub fn status_exclusive<F>(self, status: F) -> Self
where F: for<'m> StatusSync<&'m mut M, M> + Send + Sync + 'static,

Define the function giving the status of the device, with an exclusive access to the model, see Self::status.

Source

pub fn status_async_with<F>(self, status: F) -> Self
where F: for<'a> Fn(&'a M, &'a Dev<M>) -> BoxFuture<'a, Result<Scalar<str>>> + Send + Sync + 'static,

Define the function giving the status of the device, asynchronously and with a shared access to the model. This is the raw form of Self::status_async, see Self::state_async_with.

Source

pub fn status_async<F>(self, status: F) -> Self
where F: for<'a> StatusAsync<'a, &'a M, M> + Send + Sync + 'static,

Define the function giving the status of the device, asynchronously and with a shared access to the model, see Self::state_async.

Source

pub fn status_exclusive_async_with<F>(self, status: F) -> Self
where F: for<'a> Fn(&'a mut M, &'a Dev<M>) -> BoxFuture<'a, Result<Scalar<str>>> + Send + Sync + 'static,

Define the function giving the status of the device, asynchronously and with an exclusive access to the model. This is the raw form of Self::status_exclusive_async, see Self::state_async_with.

Source

pub fn status_exclusive_async<F>(self, status: F) -> Self
where F: for<'a> StatusAsync<'a, &'a mut M, M> + Send + Sync + 'static,

Define the function giving the status of the device, asynchronously and with an exclusive access to the model, see Self::state_exclusive_async.

Source

pub fn command(self, def: CommandDef<M>) -> Self

Define a command every device of that class has, which is what defining a command usually means: the devices of a class have the same interface, and a device only adds to its own the part of it that its properties decide, see Dev::add_command.

§Panics

If the class already defines a command of that name, if the name is invalid, see name::check_tango_command_name, or if it is one of the commands the server answers itself, being State, Status and Init.

Source

pub fn attr(self, def: AttrDef<M>) -> Self

Define an attribute every device of that class has, see Self::command.

§Panics

If the class already defines an attribute of that name, if the name is invalid, see name::check_tango_attr_name, if it is one of the attributes the server answers itself, being State and Status, or if the definition is inconsistent: memorized without being a writable scalar of a kind that can be memorized, see AttrDef::memorized, or with a configuration giving a value to a property its kind does not support, see AttrConfig.

Source

pub fn state_config(self, config: AttrConfig) -> Self

Set the configuration the State attribute of every device of that class starts from, which the database and clients then override like the one of any attribute. The default one only gives it a label and a description.

§Panics

If the configuration gives a value to a property a state does not support, such as a bound or an event criterion, see AttrConfig.

Source

pub fn status_config(self, config: AttrConfig) -> Self

Set the configuration the Status attribute of every device of that class starts from, see Self::state_config.

§Panics

If the configuration gives a value to a property a string does not support, see Self::state_config.

Source

pub fn push_state_events( self, change: Option<bool>, archive: Option<bool>, ) -> Self

Declare that the devices of that class push the events of their State themselves, change and archive, see AttrDef::push_change_event. For each, Some(detect) declares the event pushed by the device, detect telling whether its criteria are checked against what is pushed, and None declares it not pushed.

Source

pub fn push_status_events( self, change: Option<bool>, archive: Option<bool>, ) -> Self

Declare that the devices of that class push the events of their Status themselves, see Self::push_state_events.

Trait Implementations§

Source§

impl<M: Model> Debug for ClassDef<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 ClassDef<M>

§

impl<M> !UnwindSafe for ClassDef<M>

§

impl<M> Forget for ClassDef<M>

§

impl<M> Freeze for ClassDef<M>
where InitFn<M>: Freeze, Option<DeleteFn<M>>: Freeze, Option<StateFn<M>>: Freeze, Option<StatusFn<M>>: Freeze, Vec<Arc<CommandDef<M>>>: Freeze, Vec<Arc<AttrDef<M>>>: Freeze, Arc<AttrDef<M>>: Freeze,

§

impl<M> Send for ClassDef<M>
where InitFn<M>: Send, Option<DeleteFn<M>>: Send, Option<StateFn<M>>: Send, Option<StatusFn<M>>: Send, Vec<Arc<CommandDef<M>>>: Send, Vec<Arc<AttrDef<M>>>: Send, Arc<AttrDef<M>>: Send,

§

impl<M> Sync for ClassDef<M>
where InitFn<M>: Sync, Option<DeleteFn<M>>: Sync, Option<StateFn<M>>: Sync, Option<StatusFn<M>>: Sync, Vec<Arc<CommandDef<M>>>: Sync, Vec<Arc<AttrDef<M>>>: Sync, Arc<AttrDef<M>>: Sync,

§

impl<M> Unpin for ClassDef<M>
where InitFn<M>: Unpin, Option<DeleteFn<M>>: Unpin, Option<StateFn<M>>: Unpin, Option<StatusFn<M>>: Unpin, Vec<Arc<CommandDef<M>>>: Unpin, Vec<Arc<AttrDef<M>>>: Unpin, Arc<AttrDef<M>>: Unpin,

§

impl<M> UnsafeUnpin for ClassDef<M>
where InitFn<M>: UnsafeUnpin, Option<DeleteFn<M>>: UnsafeUnpin, Option<StateFn<M>>: UnsafeUnpin, Option<StatusFn<M>>: UnsafeUnpin, Vec<Arc<CommandDef<M>>>: UnsafeUnpin, Vec<Arc<AttrDef<M>>>: UnsafeUnpin, Arc<AttrDef<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