#[macro_use]
pub mod macros;
pub mod auth;
pub mod client;
pub mod error;
pub mod rate_limit;
pub mod request;
const LOG_BODY_MAX_LEN: usize = 512;
pub fn truncate_for_log(s: &str) -> std::borrow::Cow<'_, str> {
if s.len() <= LOG_BODY_MAX_LEN {
std::borrow::Cow::Borrowed(s)
} else {
let truncated = &s[..s.floor_char_boundary(LOG_BODY_MAX_LEN)];
std::borrow::Cow::Owned(format!("{}... [truncated]", truncated))
}
}
pub use auth::{current_timestamp, Base64Format, Signer};
pub use client::{
retry_after_header, HttpClient, HttpClientBuilder, DEFAULT_POOL_SIZE, DEFAULT_TIMEOUT_MS,
};
pub use error::ApiError;
pub use rate_limit::{RateLimiter, RetryConfig};
pub use request::{QueryBuilder, Request, RequestError};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_truncate_for_log_short_string_unchanged() {
let short = "hello world";
let result = truncate_for_log(short);
assert_eq!(result.as_ref(), short);
}
#[test]
fn test_truncate_for_log_exact_limit_unchanged() {
let exact = "a".repeat(LOG_BODY_MAX_LEN);
let result = truncate_for_log(&exact);
assert_eq!(result.as_ref(), exact.as_str());
}
#[test]
fn test_truncate_for_log_over_limit_truncated() {
let long = "x".repeat(LOG_BODY_MAX_LEN + 100);
let result = truncate_for_log(&long);
assert!(result.ends_with("... [truncated]"));
assert!(result.len() < long.len());
}
#[test]
fn test_truncate_for_log_multibyte_char_boundary() {
let mut s = "a".repeat(LOG_BODY_MAX_LEN - 1);
s.push('\u{1F600}'); s.push_str("overflow");
let result = truncate_for_log(&s);
assert!(result.ends_with("... [truncated]"));
assert!(result.is_char_boundary(0));
}
}