use serde::Serialize;
#[derive(Debug, Clone, Default, Serialize)]
pub struct PgnExportOptions {
#[serde(skip_serializing_if = "Option::is_none")]
clocks: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
comments: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
variations: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
orientation: Option<bool>,
}
impl PgnExportOptions {
#[must_use]
pub fn clocks(mut self, include: bool) -> Self {
self.clocks = Some(include);
self
}
#[must_use]
pub fn comments(mut self, include: bool) -> Self {
self.comments = Some(include);
self
}
#[must_use]
pub fn variations(mut self, include: bool) -> Self {
self.variations = Some(include);
self
}
#[must_use]
pub fn orientation(mut self, include: bool) -> Self {
self.orientation = Some(include);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_serializes_to_nothing() {
assert_eq!(
serde_urlencoded::to_string(PgnExportOptions::default()).unwrap(),
""
);
}
#[test]
fn set_flags_serialize() {
let query = serde_urlencoded::to_string(
PgnExportOptions::default().clocks(true).orientation(false),
)
.unwrap();
assert_eq!(query, "clocks=true&orientation=false");
}
}