clickhouse_arrow/
prelude.rs

1//! ## Convenience exports for working with the library.
2pub use tracing::{Instrument, Span, debug, error, info, instrument, trace, trace_span, warn};
3
4pub use crate::arrow::types::SchemaConversions;
5pub use crate::errors::*;
6pub use crate::formats::{ArrowFormat, ClientFormat, NativeFormat};
7pub use crate::native::protocol::*;
8pub use crate::native::values::*;
9pub use crate::query::{ParamValue, ParsedQuery, Qid, QueryParams};
10pub use crate::schema::*;
11pub use crate::settings::*;
12pub use crate::telemetry::*;
13pub use crate::{ArrowClient, Client, ClientBuilder, CompressionMethod, NativeClient, Row, Type};
14
15// TODO: Encrypt
16/// Newtype to protect secrets from being logged
17/// A wrapper type for sensitive string data like passwords.
18///
19/// This type provides protection against accidental exposure of sensitive data
20/// in logs, debug output, or error messages. The inner value is not displayed
21/// in `Debug` or `Display` implementations.
22///
23/// # Example
24/// ```
25/// use clickhouse_arrow::prelude::Secret;
26///
27/// let password = Secret::new("my_password");
28/// println!("{:?}", password); // Prints: Secret(REDACTED)
29/// ```
30#[derive(Clone, Default, PartialEq, Eq, Hash)]
31#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
32pub struct Secret(String);
33
34impl Secret {
35    pub fn new<P: AsRef<str>>(s: P) -> Self { Self(s.as_ref().to_string()) }
36
37    #[must_use]
38    pub fn get(&self) -> &str { &self.0 }
39}
40
41impl std::fmt::Debug for Secret {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        write!(f, "Password(*****)")
44    }
45}
46
47impl<T: AsRef<str>> From<T> for Secret {
48    fn from(s: T) -> Self { Self(s.as_ref().to_string()) }
49}
50
51/// Custom Deserialize implementation to prevent storing passwords
52#[cfg(feature = "serde")]
53impl serde::Serialize for Secret {
54    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
55    where
56        S: serde::Serializer,
57    {
58        serializer.serialize_str(&format!("{self:?}"))
59    }
60}