Skip to content

Commit

Permalink
Support for simple BString powered string values (#298)
Browse files Browse the repository at this point in the history
Some time the `Bytes` type should be removed.
  • Loading branch information
Byron committed Apr 5, 2022
1 parent e3d280f commit 2381c5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions git-config/Cargo.toml
Expand Up @@ -22,6 +22,7 @@ serde_crate = { version = "1", package = "serde", optional = true }
pwd = "1.3.1"
quick-error = "2.0.0"
unicode-bom = "1.1.4"
bstr = { version = "0.2.13", default-features = false }

[dev-dependencies]
serial_test = "0.5.1"
Expand Down
28 changes: 28 additions & 0 deletions git-config/src/values.rs
@@ -1,5 +1,6 @@
//! Rust containers for valid `git-config` types.

use bstr::BStr;
use std::{borrow::Cow, convert::TryFrom, fmt::Display, str::FromStr};

use quick_error::quick_error;
Expand Down Expand Up @@ -145,6 +146,7 @@ fn b(s: &str) -> &[u8] {
s.as_bytes()
}

// TODO: remove bytes
/// Any string value
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Bytes<'a> {
Expand Down Expand Up @@ -177,6 +179,25 @@ impl<'a> From<Cow<'a, [u8]>> for Bytes<'a> {
}
}

/// Any string value
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct String<'a> {
/// The string value
pub value: Cow<'a, BStr>,
}

impl<'a> From<Cow<'a, [u8]>> for String<'a> {
#[inline]
fn from(c: Cow<'a, [u8]>) -> Self {
String {
value: match c {
Cow::Borrowed(c) => Cow::Borrowed(c.into()),
Cow::Owned(c) => Cow::Owned(c.into()),
},
}
}
}

///
pub mod path {
use std::borrow::Cow;
Expand Down Expand Up @@ -433,6 +454,13 @@ pub enum Boolean<'a> {
}

impl Boolean<'_> {
/// Return ourselves as plain bool.
pub fn to_bool(&self) -> bool {
match self {
Boolean::True(_) => true,
Boolean::False(_) => false,
}
}
/// Generates a byte representation of the value. This should be used when
/// non-UTF-8 sequences are present or a UTF-8 representation can't be
/// guaranteed.
Expand Down
15 changes: 0 additions & 15 deletions git-repository/src/repository/config.rs

This file was deleted.

0 comments on commit 2381c5d

Please sign in to comment.