strut_rabbitmq/util/field_table/
push.rs

1use crate::util::morph::Morph;
2use lapin::types::{AMQPValue, FieldTable};
3
4/// Artificial trait implemented for [`FieldTable`] to allow inserting
5/// [`AMQPValue`]s infallibly instantiated from most applicable types.
6pub trait Push<T> {
7    /// Inserts into this [`FieldTable`] under the given `key` an [`AMQPValue`]
8    /// instantiated from the given `value`.
9    fn push(&mut self, key: &str, value: T);
10}
11
12/// Implements [`Push`] for every type `T` for which the underlying
13/// [`AMQPValue`] implements [`MapFrom`].
14impl<T> Push<T> for FieldTable
15where
16    AMQPValue: Morph<T>,
17{
18    fn push(&mut self, key: &str, value: T) {
19        self.insert(key.into(), AMQPValue::morph(value));
20    }
21}