temporal_sdk_core_protos/
utilities.rs1use std::collections::HashMap;
2
3use prost::{EncodeError, Message};
4
5pub trait TryIntoOrNone<F, T> {
6 fn try_into_or_none(self) -> Option<T>;
9}
10
11impl<F, T> TryIntoOrNone<F, T> for Option<F>
12where
13 F: TryInto<T>,
14{
15 fn try_into_or_none(self) -> Option<T> {
16 self.map(TryInto::try_into).transpose().ok().flatten()
17 }
18}
19
20pub fn pack_any<T: Message>(
24 type_url: String,
25 msg: &T,
26) -> Result<prost_wkt_types::Any, EncodeError> {
27 let mut value = Vec::new();
28 Message::encode(msg, &mut value)?;
29 Ok(prost_wkt_types::Any { type_url, value })
30}
31
32pub fn normalize_http_headers(headers: HashMap<String, String>) -> HashMap<String, String> {
35 let mut new_headers = HashMap::new();
36 for (header_key, val) in headers.into_iter() {
37 new_headers.insert(header_key.to_lowercase(), val);
38 }
39 new_headers
40}