Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #99 from golemcloud/duration-into-value
Browse files Browse the repository at this point in the history
IntoValue for Duration and Instant
  • Loading branch information
vigoo authored Dec 2, 2024
2 parents 5eb9efc + 5f5a5cb commit e9c0f39
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions wasm-rpc/src/type_annotated_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<T: Into<Type>>(value: &Value, typ: T) -> Result<Self, Vec<String>>;
}
Expand Down

0 comments on commit e9c0f39

Please sign in to comment.