EventStoreDB-Client-Rust icon indicating copy to clipboard operation
EventStoreDB-Client-Rust copied to clipboard

EventData::json should take payload by shared reference

Open hseeberger opened this issue 1 year ago • 0 comments

Currently the signature of EventData::json looks like this:

pub fn json<S, P>(event_type: S, payload: P) -> serde_json::Result<EventData>

The payload is later only used by shared reference, there is no need for an owned value:

let payload = Bytes::from(serde_json::to_vec(&payload)?);

Therefore the signature could be changed (notice &P instead of P):

pub fn json<S, P>(event_type: S, payload: &P) -> serde_json::Result<EventData>

This would avoid cloning the event in cases where it is needed after invoking EventData::json.

hseeberger avatar May 14 '24 13:05 hseeberger