Merge remote-tracking branch 'seb/sebastinez/fileDiff-path'

* seb/sebastinez/fileDiff-path:
  surf: Add `FileDiff::path` method

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
Fintan Halpenny
2023-07-24 18:16:09 +01:00
+18 -1
View File
@@ -17,7 +17,12 @@
//! Types that represent diff(s) in a Git repo. //! Types that represent diff(s) in a Git repo.
use std::{borrow::Cow, ops::Range, path::PathBuf, string::FromUtf8Error}; use std::{
borrow::Cow,
ops::Range,
path::{Path, PathBuf},
string::FromUtf8Error,
};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{ser, ser::SerializeStruct, Serialize, Serializer}; use serde::{ser, ser::SerializeStruct, Serialize, Serializer};
@@ -287,6 +292,18 @@ pub enum FileDiff {
Copied(Copied), Copied(Copied),
} }
impl FileDiff {
pub fn path(&self) -> &Path {
match self {
FileDiff::Added(x) => x.path.as_path(),
FileDiff::Deleted(x) => x.path.as_path(),
FileDiff::Modified(x) => x.path.as_path(),
FileDiff::Moved(x) => x.new_path.as_path(),
FileDiff::Copied(x) => x.new_path.as_path(),
}
}
}
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl Serialize for FileDiff { impl Serialize for FileDiff {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>