summaryrefslogtreecommitdiff
path: root/rust/proto/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/proto/src/lib.rs')
-rw-r--r--rust/proto/src/lib.rs49
1 files changed, 4 insertions, 45 deletions
diff --git a/rust/proto/src/lib.rs b/rust/proto/src/lib.rs
index 1a16c15..1a8199b 100644
--- a/rust/proto/src/lib.rs
+++ b/rust/proto/src/lib.rs
@@ -1,55 +1,12 @@
-use chrono::{DateTime, TimeZone, Utc};
+use chrono::{DateTime, Utc};
use std::ops::{Deref, DerefMut};
include!("gen/mod.rs");
-impl From<&str> for touchpad::common::v1::Gender {
- fn from(s: &str) -> Self {
- match s {
- "Male" => Self::Male,
- "Female" => Self::Female,
- _ => Self::Unspecified,
- }
- }
-}
-
-impl From<&str> for touchpad::common::v1::Stroke {
- fn from(s: &str) -> Self {
- match s {
- "Fly" => Self::Fly,
- "Back" => Self::Back,
- "Breast" => Self::Breast,
- "Free" => Self::Free,
- "Medley" => Self::Medley,
- _ => Self::Unspecified,
- }
- }
-}
-
-impl From<&str> for touchpad::common::v1::EventTimeResult {
- fn from(s: &str) -> Self {
- match s {
- "DQ" => Self::Dq,
- "DNS" => Self::Dns,
- "SCR" => Self::Scr,
- _ => Self::Unspecified,
- }
- }
-}
+//region ProtoTimestamp
pub struct ProtoTimestamp(pbjson_types::Timestamp);
-impl ProtoTimestamp {
- const TOUCHPAD_DATE_FORMAT: &'static str = "%Y-%m-%d";
-
- pub fn from_touchpad(str: &str) -> Result<Self, chrono::format::ParseError> {
- let date = chrono::NaiveDate::parse_from_str(str, ProtoTimestamp::TOUCHPAD_DATE_FORMAT)?;
- let datetime = chrono::NaiveDateTime::new(date, chrono::NaiveTime::from_hms(0, 0, 0));
-
- Ok(Utc.from_utc_datetime(&datetime).into())
- }
-}
-
impl Into<pbjson_types::Timestamp> for ProtoTimestamp {
fn into(self) -> pbjson_types::Timestamp {
self.0
@@ -75,3 +32,5 @@ impl DerefMut for ProtoTimestamp {
&mut self.0
}
}
+
+//endregion