corsa_client/api/encoded.rs
1use serde::{Deserialize, Serialize};
2
3/// Opaque binary payload returned by binary Corsa endpoints.
4///
5/// # Examples
6///
7/// ```
8/// use corsa_client::EncodedPayload;
9///
10/// let payload = EncodedPayload::new(vec![1, 2, 3]);
11/// assert_eq!(payload.as_bytes(), &[1, 2, 3]);
12/// assert_eq!(payload.clone().into_bytes(), vec![1, 2, 3]);
13/// ```
14#[derive(Clone, Debug, Eq, PartialEq)]
15pub struct EncodedPayload(Vec<u8>);
16
17impl EncodedPayload {
18 /// Wraps raw bytes returned by Corsa.
19 pub fn new(bytes: Vec<u8>) -> Self {
20 Self(bytes)
21 }
22
23 /// Borrows the payload as a byte slice.
24 pub fn as_bytes(&self) -> &[u8] {
25 &self.0
26 }
27
28 /// Consumes the wrapper and returns the underlying bytes.
29 pub fn into_bytes(self) -> Vec<u8> {
30 self.0
31 }
32}
33
34/// Formatting knobs accepted by the `printNode` endpoint.
35#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
36pub struct PrintNodeOptions {
37 /// Preserve original source newlines where the printer can do so safely.
38 #[serde(skip_serializing_if = "std::ops::Not::not")]
39 pub preserve_source_newlines: bool,
40 /// Avoid ASCII-escaping non-ASCII characters in emitted text.
41 #[serde(skip_serializing_if = "std::ops::Not::not")]
42 pub never_ascii_escape: bool,
43 /// Force literal termination when the source text would otherwise be
44 /// unterminated.
45 #[serde(skip_serializing_if = "std::ops::Not::not")]
46 pub terminate_unterminated_literals: bool,
47}