devhub_sdk/
lib.rs

1mod link_base;
2
3pub use hdk_extensions::hdi;
4pub use hdk_extensions::holo_hash;
5pub use hdk_extensions::hdk;
6pub use hdk_extensions::hdi_extensions;
7pub use hdk_extensions;
8pub use hc_crud;
9pub use link_base::*;
10
11use hdk::prelude::*;
12use hdk::hash_path::path::{
13    Path, Component,
14};
15
16
17
18/// Get a microsecond timestamp of now
19pub fn timestamp() -> ExternResult<u64> {
20    Ok( sys_time().map( |t| (t.as_micros() / 1000) as u64 )? )
21}
22
23
24pub struct PathInput(pub Vec<Component>);
25
26impl From<Vec<Component>> for PathInput {
27    fn from(input: Vec<Component>) -> Self {
28        Self(input)
29    }
30}
31
32impl From<Vec<&str>> for PathInput {
33    fn from(input: Vec<&str>) -> Self {
34        Self(
35            input.into_iter()
36                .map( |seg| Component::new( seg.as_bytes().to_vec() ) )
37                .collect()
38        )
39    }
40}
41
42impl From<&[&str]> for PathInput {
43    fn from(input: &[&str]) -> Self {
44        Self::from( input.to_vec() )
45    }
46}
47
48impl From<Vec<String>> for PathInput {
49    fn from(input: Vec<String>) -> Self {
50        Self::from(
51            input.iter()
52                .map( |seg| seg.as_str() )
53                .collect::<Vec<&str>>()
54        )
55    }
56}
57
58impl From<&[String]> for PathInput {
59    fn from(input: &[String]) -> Self {
60        Self::from( input.to_vec() )
61    }
62}
63
64impl From<&str> for PathInput {
65    fn from(input: &str) -> Self {
66        Self::from(
67            input.split(".")
68                .collect::<Vec<&str>>()
69        )
70    }
71}
72
73impl From<String> for PathInput {
74    fn from(input: String) -> Self {
75        Self::from( input.as_str() )
76    }
77}
78
79impl TryFrom<PathInput> for AnyLinkableHash {
80    type Error = WasmError;
81
82    fn try_from(input: PathInput) -> ExternResult<Self> {
83        Ok( path( input ).path_entry_hash()?.into() )
84    }
85}
86
87pub fn path<T>(input: T) -> Path
88where
89    PathInput: From<T>,
90{
91    Path::from( PathInput::from(input).0 )
92}
93
94
95#[derive(Clone, Debug, Serialize, Deserialize)]
96pub struct MoveLinkInput<T> {
97    pub from: T,
98    pub to: T,
99}