diff --git a/radicle-surf/src/diff.rs b/radicle-surf/src/diff.rs index 98c9315..a28cf95 100644 --- a/radicle-surf/src/diff.rs +++ b/radicle-surf/src/diff.rs @@ -17,7 +17,7 @@ //! Types that represent diff(s) in a Git repo. -use std::path::PathBuf; +use std::{borrow::Cow, path::PathBuf, string::FromUtf8Error}; #[cfg(feature = "serde")] use serde::{ser, ser::SerializeStruct, Serialize, Serializer}; @@ -338,6 +338,20 @@ impl From>> for Hunks { #[derive(Clone, Debug, PartialEq, Eq)] pub struct Line(pub(crate) Vec); +impl Line { + pub fn as_bytes(&self) -> &[u8] { + self.0.as_slice() + } + + pub fn from_utf8(self) -> Result { + String::from_utf8(self.0) + } + + pub fn from_utf8_lossy(&self) -> Cow { + String::from_utf8_lossy(&self.0) + } +} + impl From> for Line { fn from(v: Vec) -> Self { Self(v)