pub struct ContentHasher;Expand description
Content hasher for deduplication.
Normalizes content and produces SHA256 hashes for exact match detection.
§Normalization
Before hashing, content is normalized:
- Trimmed of leading/trailing whitespace
- Converted to lowercase
- Multiple whitespace characters collapsed to single spaces
§Example
use subcog::services::deduplication::ContentHasher;
let hash = ContentHasher::hash("Use PostgreSQL for primary storage");
assert_eq!(hash.len(), 64); // SHA256 produces 64 hex chars
// Normalized content produces the same hash
let hash2 = ContentHasher::hash(" Use postgresql for primary storage ");
assert_eq!(hash, hash2);Implementations§
Source§impl ContentHasher
impl ContentHasher
Sourcepub fn hash_to_tag(hash: &str) -> String
pub fn hash_to_tag(hash: &str) -> String
Converts a hash to a tag format.
The tag format is hash:sha256:<16-char-prefix>.
§Arguments
hash- The full SHA256 hash
§Returns
The hash tag string.
§Panics
Does not panic. If the hash is shorter than 16 chars, uses the full hash.
§Example
use subcog::services::deduplication::ContentHasher;
let hash = ContentHasher::hash("test content");
let tag = ContentHasher::hash_to_tag(&hash);
assert!(tag.starts_with("hash:sha256:"));
assert_eq!(tag.len(), "hash:sha256:".len() + 16);Sourcepub fn content_to_tag(content: &str) -> String
pub fn content_to_tag(content: &str) -> String
Computes a hash and returns it in tag format.
Convenience method that combines hash() and hash_to_tag().
§Arguments
content- The content to hash
§Returns
The hash tag string.
§Example
use subcog::services::deduplication::ContentHasher;
let tag = ContentHasher::content_to_tag("Use PostgreSQL");
assert!(tag.starts_with("hash:sha256:"));Sourcepub fn normalize(content: &str) -> String
pub fn normalize(content: &str) -> String
Normalizes content for consistent hashing.
Normalization steps:
- Trim leading/trailing whitespace
- Convert to lowercase
- Collapse multiple whitespace to single space
§Arguments
content- The content to normalize
§Returns
The normalized content string.
§Example
use subcog::services::deduplication::ContentHasher;
let normalized = ContentHasher::normalize(" Hello WORLD ");
assert_eq!(normalized, "hello world");Auto Trait Implementations§
impl Freeze for ContentHasher
impl RefUnwindSafe for ContentHasher
impl Send for ContentHasher
impl Sync for ContentHasher
impl Unpin for ContentHasher
impl UnwindSafe for ContentHasher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].