From 9ed03753c25264094e0b98c14a92f2012f89abcf Mon Sep 17 00:00:00 2001 From: Raimundo Saona <37874270+saona-raimundo@users.noreply.github.com> Date: Wed, 22 Dec 2021 13:28:00 +0100 Subject: [PATCH] Common traits for Features --- Cargo.toml | 1 + src/lib.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ef4beef..4ed7590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ dyn-clonable = "0.9" lazy_static = "1" log = "0.4" thiserror = "1" +serde = { version = "1.0", optional = true, features = ["derive"] } [dev-dependencies] env_logger = "0.9" diff --git a/src/lib.rs b/src/lib.rs index 1b7b5db..0dbdea4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ use std::boxed::Box; use std::collections::HashMap; #[cfg(target_os = "macos")] use std::ffi::CStr; +use std::fmt; use std::sync::Mutex; #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -84,13 +85,15 @@ unsafe impl Send for UtteranceId {} unsafe impl Sync for UtteranceId {} +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Features { - pub stop: bool, - pub rate: bool, - pub pitch: bool, - pub volume: bool, pub is_speaking: bool, + pub pitch: bool, + pub rate: bool, + pub stop: bool, pub utterance_callbacks: bool, + pub volume: bool, } impl Default for Features { @@ -106,6 +109,18 @@ impl Default for Features { } } +impl fmt::Display for Features { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + writeln!(f, "{:#?}", self) + } +} + +impl Features { + pub fn new() -> Self { + Self::default() + } +} + #[derive(Debug, Error)] pub enum Error { #[error("IO error: {0}")]