pub fn publish_to_topic<T>(&self, topic: &str, message: &T) -> Result<(), IoError>
    where
        T: Debug + DeserializeOwned + Serialize + 'static,
    {
        if !self.config.has_pubsub(topic) {
            return Err(IoError::new(
                ErrorKind::NotFound,
                format!("PubSub topic not in config: {}", topic),
            ));
        }

        // TODO make it not necessary to do this every message. Needs refactoring usage of generic
        // parameters in the Publisher struct.
        let topic_name = Process::config_name(&self.name, topic);
        let mut publisher = Publisher::<T>::new(&topic_name);
        for config in self.config.get_pubsub_topic(topic).unwrap().iter() {
            if let Some(addr) = config.udp() {
                publisher.add_udp_endpoint(addr);
            } else if let Some(name) = config.unix() {
                let socket_path = match &self.run_dir {
                    Some(dir) => config::unix_socket_dir(&dir)
                        .as_path()
                        .join(Process::config_name(&name, topic)),
                    None => {
                        return Err(IoError::new(
                            ErrorKind::Unsupported,
                            format!("Process {} has no run directory", self.name),
                        ));
                    }
                };
                publisher.add_unix_datagram_endpoint(&socket_path);
            } else {
                panic!("impossible");
            }
        }

        publisher.publish(message);
        Ok(())
    }
/// Publish a message to a topic.
///
/// The topic must be defined in the `Process` config. Additionally, if publishing to a Unix
/// socket, the run directory for the proces must exist.
///
/// Args:
/// * `topic`: The PubSub topic to publish to.
/// * `message`: The data to publish.
Publish a message to a topic.
The topic must be defined in the `Process` config. Additionally, if publishing to a Unix
socket, the run directory for the proces must exist.

`topic`: The PubSub topic to publish to.
`message`: The data to publish.
Publish a message to a topic . The topic must be defined in the ` Process ` config . Additionally if publishing to a Unix socket the run directory for the proces must exist . ` topic ` : The PubSub topic to publish to . ` message ` : The data to publish .
pub fn publish_to_topic<T>(&self, topic: &str, message: &T) -> Result<(), IoError>
    where
        T: Debug + DeserializeOwned + Serialize + 'static,
    {
        if !self.config.has_pubsub(topic) {
            return Err(IoError::new(
                ErrorKind::NotFound,
                format!("PubSub topic not in config: {}", topic),
            ));
        }
        // TODO make it not necessary to do this every message. Needs refactoring usage of generic
        // parameters in the Publisher struct.
        let topic_name = Process::config_name(&self.name, topic);
        let mut publisher = Publisher::<T>::new(&topic_name);
        for config in self.config.get_pubsub_topic(topic).unwrap().iter() {
            if let Some(addr) = config.udp() {
                publisher.add_udp_endpoint(addr);
            } else if let Some(name) = config.unix() {
                let socket_path = match &self.run_dir {
                    Some(dir) => config::unix_socket_dir(&dir)
                        .as_path()
                        .join(Process::config_name(&name, topic)),
                    None => {
                        return Err(IoError::new(
                            ErrorKind::Unsupported,
                            format!("Process {} has no run directory", self.name),
                        ));
                    }
                };
                publisher.add_unix_datagram_endpoint(&socket_path);
            } else {
                panic!("impossible");
            }
        }
        publisher.publish(message);
        Ok(())
    }
pub fn publish_to_topic < T > ( & self , topic : & str , message : & T ) -> Result < ( ) , IoError > where T : Debug + DeserializeOwned + Serialize + ' static , { if ! self . config . has_pubsub ( topic ) { return Err ( IoError :: new ( ErrorKind :: NotFound , format ! ( " " topic ) , ) ) ; } // TODO make it not necessary to do this every message. Needs refactoring usage of generic // parameters in the Publisher struct. let topic_name = Process :: config_name ( & self . name , topic ) ; let mut publisher = Publisher :: < T > :: new ( & topic_name ) ; for config in self . config . get_pubsub_topic ( topic ) . unwrap ( ) . iter ( ) { if let Some ( addr ) = config . udp ( ) { publisher . add_udp_endpoint ( addr ) ; } else if let Some ( name ) = config . unix ( ) { let socket_path = match & self . run_dir { Some ( dir ) => config :: unix_socket_dir ( & dir ) . as_path ( ) . join ( Process :: config_name ( & name , topic ) ) , None => { return Err ( IoError :: new ( ErrorKind :: Unsupported , format ! ( " " self name ) , ) ) ; } } ; publisher . add_unix_datagram_endpoint ( & socket_path ) ; } else { panic ! ( " " ) ; } } publisher . publish ( message ) ; Ok ( ( ) ) }
Publish a message to a topic.
Publish a message to a topic .
&self
topic
&str
message
&T
&self
topic
&str
message
&T