epics_ca/channel/
mod.rs

1//! There are three kinds of channels:
2//!
3//! + [`Channel`] - raw channel without knowledge of what is inside.
4//! + [`TypedChannel`] - channel that knows type of its items and whether it is scalar or array. Created with [`Channel::into_typed`].
5//! + [`ValueChannel`] - convenience wrapper around [`TypedChannel`].
6//!   Recommended to use when you need PV values only, not metadata. Created by [`Context::connect`] or [`TypedChannel::into_value`].
7//!
8
9pub mod base;
10pub mod get;
11pub mod put;
12pub mod subscribe;
13pub mod typed;
14pub mod value;
15
16pub use base::{Channel, Connect};
17pub use get::{Get, GetFn};
18pub use put::Put;
19pub use subscribe::Subscription;
20pub use typed::TypedChannel;
21pub use value::ValueChannel;
22
23use crate::{context::Context, error::Error, types::Value};
24use std::ffi::CStr;
25
26impl Context {
27    /// Create channel, wait for connection, and try to cast it to typed one.
28    pub async fn connect<V: Value + ?Sized>(&self, name: &CStr) -> Result<ValueChannel<V>, Error> {
29        let mut chan = Channel::new(self, name)?;
30        chan.connected().await;
31        let typed = chan.into_typed::<V>().map_err(|(err, _)| err)?;
32        Ok(typed.into_value())
33    }
34}
35
36#[cfg(test)]
37mod tests;