summaryrefslogtreecommitdiff
path: root/rust/proto/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@yahoo.com> 2022-08-15 15:24:06 -0700
committerGravatar Anshul Gupta <ansg191@yahoo.com> 2022-08-15 15:25:55 -0700
commitedc5985b1744dcffb8bf1b41ce273508573589fe (patch)
treeb57bf381454957e991ffde347cafae4e2d4d9deb /rust/proto/src/lib.rs
parentb26ffd01b821047b692e5235e4f7f4f8f535f432 (diff)
downloadtouchpad-edc5985b1744dcffb8bf1b41ce273508573589fe.tar.gz
touchpad-edc5985b1744dcffb8bf1b41ce273508573589fe.tar.zst
touchpad-edc5985b1744dcffb8bf1b41ce273508573589fe.zip
Adds rust touchpad scraper
Implements meet, events, and swimmers api in touchpad live. Also implements protobuf generation into rust crate.
Diffstat (limited to 'rust/proto/src/lib.rs')
-rw-r--r--rust/proto/src/lib.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/rust/proto/src/lib.rs b/rust/proto/src/lib.rs
new file mode 100644
index 0000000..1a16c15
--- /dev/null
+++ b/rust/proto/src/lib.rs
@@ -0,0 +1,77 @@
+use chrono::{DateTime, TimeZone, 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,
+ }
+ }
+}
+
+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
+ }
+}
+
+impl From<DateTime<Utc>> for ProtoTimestamp {
+ fn from(dt: DateTime<Utc>) -> Self {
+ ProtoTimestamp(dt.into())
+ }
+}
+
+impl Deref for ProtoTimestamp {
+ type Target = pbjson_types::Timestamp;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl DerefMut for ProtoTimestamp {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}