jsont.rs (ripgrep-12.1.1) | : | jsont.rs (ripgrep-13.0.0) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
// convenient for deserialization however, so these types would become a bit | // convenient for deserialization however, so these types would become a bit | |||
// more complex. | // more complex. | |||
use std::borrow::Cow; | use std::borrow::Cow; | |||
use std::path::Path; | use std::path::Path; | |||
use std::str; | use std::str; | |||
use base64; | use base64; | |||
use serde::{Serialize, Serializer}; | use serde::{Serialize, Serializer}; | |||
use stats::Stats; | use crate::stats::Stats; | |||
#[derive(Serialize)] | #[derive(Serialize)] | |||
#[serde(tag = "type", content = "data")] | #[serde(tag = "type", content = "data")] | |||
#[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | |||
pub enum Message<'a> { | pub enum Message<'a> { | |||
Begin(Begin<'a>), | Begin(Begin<'a>), | |||
End(End<'a>), | End(End<'a>), | |||
Match(Match<'a>), | Match(Match<'a>), | |||
Context(Context<'a>), | Context(Context<'a>), | |||
} | } | |||
skipping to change at line 93 | skipping to change at line 93 | |||
Text { | Text { | |||
text: Cow<'a, str>, | text: Cow<'a, str>, | |||
}, | }, | |||
Bytes { | Bytes { | |||
#[serde(serialize_with = "to_base64")] | #[serde(serialize_with = "to_base64")] | |||
bytes: &'a [u8], | bytes: &'a [u8], | |||
}, | }, | |||
} | } | |||
impl<'a> Data<'a> { | impl<'a> Data<'a> { | |||
fn from_bytes(bytes: &[u8]) -> Data { | fn from_bytes(bytes: &[u8]) -> Data<'_> { | |||
match str::from_utf8(bytes) { | match str::from_utf8(bytes) { | |||
Ok(text) => Data::Text { text: Cow::Borrowed(text) }, | Ok(text) => Data::Text { text: Cow::Borrowed(text) }, | |||
Err(_) => Data::Bytes { bytes }, | Err(_) => Data::Bytes { bytes }, | |||
} | } | |||
} | } | |||
#[cfg(unix)] | #[cfg(unix)] | |||
fn from_path(path: &Path) -> Data { | fn from_path(path: &Path) -> Data<'_> { | |||
use std::os::unix::ffi::OsStrExt; | use std::os::unix::ffi::OsStrExt; | |||
match path.to_str() { | match path.to_str() { | |||
Some(text) => Data::Text { text: Cow::Borrowed(text) }, | Some(text) => Data::Text { text: Cow::Borrowed(text) }, | |||
None => Data::Bytes { bytes: path.as_os_str().as_bytes() }, | None => Data::Bytes { bytes: path.as_os_str().as_bytes() }, | |||
} | } | |||
} | } | |||
#[cfg(not(unix))] | #[cfg(not(unix))] | |||
fn from_path(path: &Path) -> Data { | fn from_path(path: &Path) -> Data { | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added |