golem_common/
lib.rs

1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Golem Source License v1.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://license.golem.cloud/LICENSE
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::convert::Infallible;
16use std::fmt;
17use std::fmt::{Display, Formatter};
18
19#[cfg(feature = "base-model")]
20pub mod base_model;
21
22#[cfg(feature = "tokio")]
23pub mod cache;
24
25#[cfg(feature = "protobuf")]
26pub mod client;
27
28#[cfg(feature = "config")]
29pub mod config;
30
31pub mod golem_version;
32
33#[cfg(feature = "protobuf")]
34pub mod grpc;
35
36#[cfg(feature = "poem")]
37pub mod json_yaml;
38
39#[cfg(feature = "observability")]
40pub mod metrics;
41
42#[cfg(feature = "model")]
43pub mod model;
44
45#[cfg(any(feature = "model", feature = "base-model"))]
46pub mod newtype;
47
48#[cfg(feature = "redis")]
49pub mod redis;
50
51#[cfg(feature = "sql")]
52pub mod repo;
53
54#[cfg(feature = "tokio")]
55pub mod retriable_error;
56
57#[cfg(feature = "tokio")]
58pub mod retries;
59
60#[cfg(feature = "serialization")]
61pub mod serialization;
62
63#[cfg(feature = "observability")]
64pub mod tracing;
65
66#[cfg(feature = "model")]
67pub mod virtual_exports;
68
69#[cfg(test)]
70test_r::enable!();
71
72/// Trait to convert a value to a string which is safe to return through a public API.
73pub trait SafeDisplay {
74    fn to_safe_string(&self) -> String;
75}
76
77pub struct SafeString(String);
78
79impl SafeDisplay for SafeString {
80    fn to_safe_string(&self) -> String {
81        self.0.clone()
82    }
83}
84
85impl Display for SafeString {
86    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
87        write!(f, "{}", self.0)
88    }
89}
90
91pub fn safe(value: String) -> impl SafeDisplay {
92    SafeString(value)
93}
94
95pub fn widen_infallible<T>(_inf: Infallible) -> T {
96    panic!("impossible")
97}