From 1ca3ed700d03228e52775c8d9f5d33eb62579772 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 3 May 2023 16:09:49 +0100 Subject: [PATCH 1/2] surf: improve Line API Adds several methods to Line: * as_bytes -- gets the underlying bytes * from_utf8 -- convert the Line to a String * from_utf8_lossy -- convert Line to Cow Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-surf/src/diff.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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) From 9d44dacdaef125e7b0641899664f57b52e2f337c Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 3 May 2023 20:06:40 +0100 Subject: [PATCH 2/2] publish: radicle-git-ext and radicle-surf Publish new versions: * radicle-git-ext 0.4.0 * radicle-surf 0.10.0 Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-git-ext/Cargo.toml | 2 +- radicle-surf/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/radicle-git-ext/Cargo.toml b/radicle-git-ext/Cargo.toml index b930fd4..b858617 100644 --- a/radicle-git-ext/Cargo.toml +++ b/radicle-git-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radicle-git-ext" -version = "0.3.0" +version = "0.4.0" authors = [ "Alexis Sellier ", "Kim Altintop ", diff --git a/radicle-surf/Cargo.toml b/radicle-surf/Cargo.toml index 79048a6..80ce60e 100644 --- a/radicle-surf/Cargo.toml +++ b/radicle-surf/Cargo.toml @@ -2,7 +2,7 @@ name = "radicle-surf" description = "A code surfing library for Git repositories" readme = "README.md" -version = "0.9.0" +version = "0.10.0" authors = ["The Radicle Team "] edition = "2021" homepage = "https://github.com/radicle-dev/radicle-surf" @@ -38,7 +38,7 @@ default-features = false features = ["vendored-libgit2"] [dependencies.radicle-git-ext] -version = "0.3.0" +version = "0.4.0" path = "../radicle-git-ext" features = ["serde"]