From 43c35641877b5dc2e92b5af80d18d24df3d00d0f Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 24 Jul 2023 15:40:49 +0200 Subject: [PATCH] surf: Add `FileDiff::path` method This allows to get the latest path of a `FileDiff`, directly from `radicle_surf` Signed-off-by: Sebastian Martinez --- radicle-surf/src/diff.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/radicle-surf/src/diff.rs b/radicle-surf/src/diff.rs index f8fe509..143cbcf 100644 --- a/radicle-surf/src/diff.rs +++ b/radicle-surf/src/diff.rs @@ -17,7 +17,12 @@ //! 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")] use serde::{ser, ser::SerializeStruct, Serialize, Serializer}; @@ -287,6 +292,18 @@ pub enum FileDiff { 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")] impl Serialize for FileDiff { fn serialize(&self, serializer: S) -> Result