Skip to content

Commit

Permalink
chore(buffers): fix unconstrained generic parameter in EventCount i…
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz authored May 25, 2022
1 parent a2fde4e commit 3293ebb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
14 changes: 10 additions & 4 deletions lib/vector-buffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ pub trait EventCount {
fn event_count(&self) -> usize;
}

impl<T> EventCount for Vec<T> {
impl<T> EventCount for Vec<T>
where
T: EventCount,
{
fn event_count(&self) -> usize {
self.len()
self.iter().map(EventCount::event_count).sum()
}
}

impl<T> EventCount for &Vec<T> {
impl<'a, T> EventCount for &'a T
where
T: EventCount,
{
fn event_count(&self) -> usize {
self.len()
(*self).event_count()
}
}

Expand Down
18 changes: 9 additions & 9 deletions lib/vector-common/src/byte_size_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ pub trait ByteSizeOf {
fn allocated_bytes(&self) -> usize;
}

impl<'a, T> ByteSizeOf for &'a T
where
T: ByteSizeOf,
{
fn allocated_bytes(&self) -> usize {
(*self).size_of()
}
}

impl ByteSizeOf for Bytes {
fn allocated_bytes(&self) -> usize {
self.len()
Expand Down Expand Up @@ -102,15 +111,6 @@ where
}
}

impl<T> ByteSizeOf for &Vec<T>
where
T: ByteSizeOf,
{
fn allocated_bytes(&self) -> usize {
self.iter().map(ByteSizeOf::size_of).sum()
}
}

impl<T, const N: usize> ByteSizeOf for [T; N]
where
T: ByteSizeOf,
Expand Down
16 changes: 0 additions & 16 deletions lib/vector-core/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,12 @@ impl ByteSizeOf for Event {
}
}

impl ByteSizeOf for &Event {
fn allocated_bytes(&self) -> usize {
match self {
Event::Log(log_event) => log_event.allocated_bytes(),
Event::Metric(metric_event) => metric_event.allocated_bytes(),
Event::Trace(trace_event) => trace_event.allocated_bytes(),
}
}
}

impl EventCount for Event {
fn event_count(&self) -> usize {
1
}
}

impl EventCount for &Event {
fn event_count(&self) -> usize {
1
}
}

impl Finalizable for Event {
fn take_finalizers(&mut self) -> EventFinalizers {
match self {
Expand Down
8 changes: 8 additions & 0 deletions src/sinks/loki/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::HashMap, io};

use bytes::Bytes;
use serde::{ser::SerializeSeq, Serialize};
use vector_buffers::EventCount;
use vector_core::{
event::{EventFinalizers, Finalizable},
ByteSizeOf,
Expand Down Expand Up @@ -93,6 +94,13 @@ impl ByteSizeOf for LokiRecord {
}
}

impl EventCount for LokiRecord {
fn event_count(&self) -> usize {
// A Loki record is mapped one-to-one with an event.
1
}
}

impl Finalizable for LokiRecord {
fn take_finalizers(&mut self) -> EventFinalizers {
std::mem::take(&mut self.finalizers)
Expand Down

0 comments on commit 3293ebb

Please sign in to comment.