From 5f5a5cb7d3da414fc7cc93520b5bddb62d38e3ad Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 2 Dec 2024 14:05:49 +0100 Subject: [PATCH] IntoValue for Duration and Instant --- wasm-rpc/src/type_annotated_value.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wasm-rpc/src/type_annotated_value.rs b/wasm-rpc/src/type_annotated_value.rs index d8c2becc..ca719db9 100644 --- a/wasm-rpc/src/type_annotated_value.rs +++ b/wasm-rpc/src/type_annotated_value.rs @@ -13,6 +13,7 @@ use golem_wasm_ast::analysis::analysed_type::{ use golem_wasm_ast::analysis::protobuf::Type; use golem_wasm_ast::analysis::AnalysedType; use std::collections::HashMap; +use std::time::{Duration, Instant}; use uuid::Uuid; #[derive(Clone, Debug, PartialEq)] @@ -510,6 +511,26 @@ impl IntoValue for Uri { } } +impl IntoValue for Instant { + fn into_value(self) -> Value { + Value::U64(self.elapsed().as_nanos() as u64) + } + + fn get_type() -> AnalysedType { + u64() + } +} + +impl IntoValue for Duration { + fn into_value(self) -> Value { + Value::U64(self.as_nanos() as u64) + } + + fn get_type() -> AnalysedType { + u64() + } +} + pub trait TypeAnnotatedValueConstructors: Sized { fn create>(value: &Value, typ: T) -> Result>; }