Take &str instead of String for HxEvent::new_* fns

This commit is contained in:
Rob Wagner 2023-10-23 21:04:06 -04:00
parent 22e81e0d0b
commit 3928b9f407
No known key found for this signature in database
GPG key ID: 53CCB4497B15CF61

View file

@ -161,14 +161,17 @@ pub struct HxEvent {
impl HxEvent {
pub fn new<T: Serialize>(name: String) -> Self {
Self { name, data: None }
Self {
name: name.to_string(),
data: None,
}
}
pub fn new_with_data<T: Serialize>(name: String, data: T) -> Result<Self, serde_json::Error> {
pub fn new_with_data<T: Serialize>(name: &str, data: T) -> Result<Self, serde_json::Error> {
let data = serde_json::to_value(data)?;
Ok(Self {
name,
name: name.to_string(),
data: Some(data),
})
}