kingfisher/src/validation_body.rs
Mick Grove 078fa16e6a - Reduced per-match memory usage by compacting stored source locations and interning repeated capture names.
- Stored optional validation response bodies as boxed strings to avoid allocating empty payloads and to streamline validator caches.
- Parallelized git cloning based on the configured job count and begin scanning repositories as soon as each clone finishes to reduce end-to-end scan times.
- Combined per-repository results into a single aggregate summary after scans complete.
- Added initial access-map support and report viewer html file. Currently beta features.
2025-12-04 22:02:30 -08:00

46 lines
1.2 KiB
Rust

use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use serde::{Deserialize, Deserializer, Serializer};
use std::borrow::Cow;
/// Storage for validation response payloads. `None` avoids heap allocation when validation is
/// disabled or produces no body.
pub type ValidationResponseBody = Option<Box<str>>;
#[inline]
pub fn from_string(body: impl Into<String>) -> ValidationResponseBody {
let body = body.into();
if body.is_empty() {
None
} else {
Some(body.into_boxed_str())
}
}
#[inline]
pub fn as_str(body: &ValidationResponseBody) -> &str {
body.as_deref().unwrap_or("")
}
#[inline]
pub fn clone_as_string(body: &ValidationResponseBody) -> String {
as_str(body).to_string()
}
pub fn serialize<S>(body: &ValidationResponseBody, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(as_str(body))
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<ValidationResponseBody, D::Error>
where
D: Deserializer<'de>,
{
let body: Cow<'de, str> = Deserialize::deserialize(deserializer)?;
Ok(from_string(body))
}
pub fn schema(gen: &mut SchemaGenerator) -> Schema {
String::json_schema(gen)
}