Skip to content

Commit

Permalink
feat: EventValues from heterogenous tuples (#11)
Browse files Browse the repository at this point in the history
So far, we were only able to serialize `Vec<T>` or iterators of `T` for
one homogenous type `T`. Users were forced to pre-create an
`EventValue::List` with inner `EventValue`s.

This commit adds `From` implementations for tuples ranging from 2 to 5
elements where each type can be a different one as long as all of them
implement `Into<EventValue>`.

Co-authored-by: Simon B. Gasse <sgasse@users.noreply.github.com>
  • Loading branch information
sgasse and sgasse committed Nov 9, 2023
1 parent 3751214 commit a4d079a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,58 @@ where
}
}

impl<T, U> From<(T, U)> for EventValue
where
T: Into<EventValue>,
U: Into<EventValue>,
{
fn from(value: (T, U)) -> Self {
EventValue::List(vec![value.0.into(), value.1.into()])
}
}

impl<T, U, V> From<(T, U, V)> for EventValue
where
T: Into<EventValue>,
U: Into<EventValue>,
V: Into<EventValue>,
{
fn from(value: (T, U, V)) -> Self {
EventValue::List(vec![value.0.into(), value.1.into(), value.2.into()])
}
}

impl<T, U, V, X> From<(T, U, V, X)> for EventValue
where
T: Into<EventValue>,
U: Into<EventValue>,
V: Into<EventValue>,
X: Into<EventValue>,
{
fn from(value: (T, U, V, X)) -> Self {
EventValue::List(vec![value.0.into(), value.1.into(), value.2.into(), value.3.into()])
}
}

impl<T, U, V, X, Y> From<(T, U, V, X, Y)> for EventValue
where
T: Into<EventValue>,
U: Into<EventValue>,
V: Into<EventValue>,
X: Into<EventValue>,
Y: Into<EventValue>,
{
fn from(value: (T, U, V, X, Y)) -> Self {
EventValue::List(vec![
value.0.into(),
value.1.into(),
value.2.into(),
value.3.into(),
value.4.into(),
])
}
}

/// Write an event with the timestamp now to `Buffer::Events`
/// ```
/// use android_logd_logger::{write_event, write_event_now, Error, Event, EventValue};
Expand Down

0 comments on commit a4d079a

Please sign in to comment.