Skip to main content

ListenerConfig

Trait ListenerConfig 

Source
pub trait ListenerConfig:
    Send
    + Sync
    + Serialize
    + Deserialize {
    // Required methods
    fn protocol(&self) -> &str;
    fn address(&self) -> &str;
    fn build(&self) -> Box<dyn ChatListener>;
    fn clone_box(&self) -> Box<dyn ListenerConfig>;
    fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result;
}
Expand description

Per-listener configuration trait.

Each protocol provides its own config struct that implements this trait. The trait is serde-compatible via typetag, so Vec<Box<dyn ListenerConfig>> can be serialized and deserialized from JSON, TOML, etc.

§Implementing a custom listener config

use chat_system::config::ListenerConfig;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MyListenerConfig { pub address: String }

#[typetag::serde(name = "my-protocol")]
impl ListenerConfig for MyListenerConfig {
    fn protocol(&self) -> &str { "my-protocol" }
    fn address(&self) -> &str { &self.address }
    fn build(&self) -> Box<dyn chat_system::server::ChatListener> { todo!() }
    fn clone_box(&self) -> Box<dyn ListenerConfig> { Box::new(self.clone()) }
    fn debug_fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Debug::fmt(self, f)
    }
}

Required Methods§

Source

fn protocol(&self) -> &str

The wire protocol this listener speaks (e.g. "irc").

Source

fn address(&self) -> &str

The address this listener will bind.

Source

fn build(&self) -> Box<dyn ChatListener>

Construct a concrete ChatListener from this config.

Source

fn clone_box(&self) -> Box<dyn ListenerConfig>

Clone this config into a new boxed trait object.

Source

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

Format this config for debug output.

Trait Implementations§

Source§

impl Clone for Box<dyn ListenerConfig>

Source§

fn clone(&self) -> Self

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

Source§

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

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

impl<'typetag> Serialize for dyn ListenerConfig + 'typetag

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<'typetag> Serialize for dyn ListenerConfig + Send + 'typetag

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<'typetag> Serialize for dyn ListenerConfig + Send + Sync + 'typetag

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<'typetag> Serialize for dyn ListenerConfig + Sync + 'typetag

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

Implementors§