1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use serde::{Serialize, Serializer};

use crate::Message;

/// Print a machine-oriented object as JSON.
///
/// In text mode, the value will be pretty-printed.
#[derive(Serialize)]
pub struct MachineMessage<T>(pub T);

impl<T> Message for MachineMessage<T>
where
    T: Serialize,
{
    fn text(self) -> String {
        serde_json::to_string_pretty(&self.0).expect("MachineData must serialize without panics")
    }

    fn structured<S: Serializer>(self, ser: S) -> Result<S::Ok, S::Error> {
        self.0.serialize(ser)
    }
}