Struct persist_es::SemanticVersionEventUpcaster
source · [−]pub struct SemanticVersionEventUpcaster { /* private fields */ }
Expand description
This upcasts any event that has the same event_type
and an event_version
that is less than the
version configured on the upcaster.
use persist_es::{EventUpcaster,SemanticVersionEventUpcaster};
use serde_json::Value;
use persist_es::SerializedEvent;
let upcast_function = Box::new(|payload: Value| match payload {
Value::Object(mut object_map) => {
object_map.insert("country".to_string(), "USA".into());
Value::Object(object_map)
}
_ => {
panic!("the event payload is not an object")
}
});
let upcaster = SemanticVersionEventUpcaster::new("EventX", "2.3.4", upcast_function);
let payload: Value = serde_json::from_str(
r#"{
"zip code": 98103,
"state": "Washington"
}"#,
).unwrap();
let event = SerializedEvent::new(
"".to_string(),
0,
"".to_string(),
"".to_string(),
"".to_string(),
payload,
Default::default(),
);
let upcasted_event = upcaster.upcast(event);
let expected_payload: Value = serde_json::from_str(
r#"{
"zip code": 98103,
"state": "Washington",
"country": "USA"
}"#,
).unwrap();
let expected_event = SerializedEvent::new(
"".to_string(),
0,
"".to_string(),
"".to_string(),
"2.3.4".to_string(),
expected_payload,
Default::default(),
);
assert_eq!(upcasted_event, expected_event);
Implementations
Trait Implementations
sourceimpl EventUpcaster for SemanticVersionEventUpcaster
impl EventUpcaster for SemanticVersionEventUpcaster
sourcefn can_upcast(&self, event_type: &str, event_version: &str) -> bool
fn can_upcast(&self, event_type: &str, event_version: &str) -> bool
Examines and event type and version to understand if the event should be upcasted.
sourcefn upcast(&self, event: SerializedEvent) -> SerializedEvent
fn upcast(&self, event: SerializedEvent) -> SerializedEvent
Modifies the serialized event to conform the the new structure.
Auto Trait Implementations
impl !RefUnwindSafe for SemanticVersionEventUpcaster
impl Send for SemanticVersionEventUpcaster
impl Sync for SemanticVersionEventUpcaster
impl Unpin for SemanticVersionEventUpcaster
impl !UnwindSafe for SemanticVersionEventUpcaster
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more