Compare commits
No commits in common. "7c29e44f20e58d48eb9ef456b37652ecb8ab0729" and "6ce2c1d89de4066faa91c0e40df566bfa200af96" have entirely different histories.
7c29e44f20
...
6ce2c1d89d
5 changed files with 35 additions and 45 deletions
16
src/file.rs
16
src/file.rs
|
@ -122,7 +122,7 @@ impl MutableValue<'_, '_, '_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An intermediate representation of a mutable multivar obtained from
|
/// An imtermediate representation of a mutable multivar obtained from
|
||||||
/// [`GitConfig`].
|
/// [`GitConfig`].
|
||||||
pub struct MutableMultiValue<'borrow, 'lookup, 'event> {
|
pub struct MutableMultiValue<'borrow, 'lookup, 'event> {
|
||||||
section: &'borrow mut HashMap<SectionId, Vec<Event<'event>>>,
|
section: &'borrow mut HashMap<SectionId, Vec<Event<'event>>>,
|
||||||
|
@ -169,7 +169,6 @@ impl<'event> MutableMultiValue<'_, '_, 'event> {
|
||||||
|
|
||||||
/// Returns the size of values the multivar has.
|
/// Returns the size of values the multivar has.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.indices_and_sizes.len()
|
self.indices_and_sizes.len()
|
||||||
}
|
}
|
||||||
|
@ -177,7 +176,6 @@ impl<'event> MutableMultiValue<'_, '_, 'event> {
|
||||||
/// Returns if the multivar has any values. This might occur if the value
|
/// Returns if the multivar has any values. This might occur if the value
|
||||||
/// was deleted but not set with a new value.
|
/// was deleted but not set with a new value.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.indices_and_sizes.is_empty()
|
self.indices_and_sizes.is_empty()
|
||||||
}
|
}
|
||||||
|
@ -1133,8 +1131,8 @@ impl Display for GitConfig<'_> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod from_parser {
|
mod from_parser {
|
||||||
use super::{Cow, Event, GitConfig, HashMap, LookupTreeNode, SectionId, TryFrom};
|
use super::*;
|
||||||
use crate::test_util::{name_event, newline_event, section_header, value_event};
|
use crate::test_util::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_empty() {
|
fn parse_empty() {
|
||||||
|
@ -1333,7 +1331,7 @@ mod from_parser {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod get_raw_value {
|
mod get_raw_value {
|
||||||
use super::{Cow, GitConfig, GitConfigError, TryFrom};
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_section() {
|
fn single_section() {
|
||||||
|
@ -1409,7 +1407,7 @@ mod get_raw_value {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod get_value {
|
mod get_value {
|
||||||
use super::{Cow, GitConfig, TryFrom};
|
use super::*;
|
||||||
use crate::values::{Boolean, TrueVariant, Value};
|
use crate::values::{Boolean, TrueVariant, Value};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
@ -1428,7 +1426,7 @@ mod get_value {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod get_raw_multi_value {
|
mod get_raw_multi_value {
|
||||||
use super::{Cow, GitConfig, GitConfigError, TryFrom};
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_value_is_identical_to_single_value_query() {
|
fn single_value_is_identical_to_single_value_query() {
|
||||||
|
@ -1517,7 +1515,7 @@ mod get_raw_multi_value {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod display {
|
mod display {
|
||||||
use super::{GitConfig, TryFrom};
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_reconstruct_empty_config() {
|
fn can_reconstruct_empty_config() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
// #![deny(missing_docs)]
|
// #![deny(missing_docs)]
|
||||||
#![warn(clippy::pedantic, clippy::nursery, clippy::cargo)]
|
#![warn(clippy::pedantic, clippy::nursery, clippy::cargo)]
|
||||||
#![allow(clippy::shadow_unrelated)]
|
#![allow(clippy::must_use_candidate, clippy::shadow_unrelated)]
|
||||||
|
|
||||||
//! # `git_config`
|
//! # `git_config`
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -69,7 +69,6 @@ pub enum Event<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event<'_> {
|
impl Event<'_> {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -97,7 +96,13 @@ impl Display for Event<'_> {
|
||||||
|
|
||||||
impl Into<Vec<u8>> for Event<'_> {
|
impl Into<Vec<u8>> for Event<'_> {
|
||||||
fn into(self) -> Vec<u8> {
|
fn into(self) -> Vec<u8> {
|
||||||
(&self).into()
|
match self {
|
||||||
|
Self::Value(e) | Self::ValueNotDone(e) | Self::ValueDone(e) => e.to_vec(),
|
||||||
|
Self::Comment(e) => e.into(),
|
||||||
|
Self::SectionHeader(e) => e.into(),
|
||||||
|
Self::Key(e) | Self::Newline(e) | Self::Whitespace(e) => e.as_bytes().to_vec(),
|
||||||
|
Self::KeyValueSeparator => vec![b'='],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +157,6 @@ pub struct ParsedSectionHeader<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParsedSectionHeader<'_> {
|
impl ParsedSectionHeader<'_> {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -245,13 +249,11 @@ pub struct Error<'a> {
|
||||||
impl Error<'_> {
|
impl Error<'_> {
|
||||||
/// The one-indexed line number where the error occurred. This is determined
|
/// The one-indexed line number where the error occurred. This is determined
|
||||||
/// by the number of newlines that were successfully parsed.
|
/// by the number of newlines that were successfully parsed.
|
||||||
#[must_use]
|
|
||||||
pub const fn line_number(&self) -> usize {
|
pub const fn line_number(&self) -> usize {
|
||||||
self.line_number + 1
|
self.line_number + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The remaining data that was left unparsed.
|
/// The remaining data that was left unparsed.
|
||||||
#[must_use]
|
|
||||||
pub const fn remaining_data(&self) -> &[u8] {
|
pub const fn remaining_data(&self) -> &[u8] {
|
||||||
self.parsed_until
|
self.parsed_until
|
||||||
}
|
}
|
||||||
|
@ -525,7 +527,6 @@ impl<'a> Parser<'a> {
|
||||||
/// a section) from the parser. Consider [`Parser::take_frontmatter`] if
|
/// a section) from the parser. Consider [`Parser::take_frontmatter`] if
|
||||||
/// you need an owned copy only once. If that function was called, then this
|
/// you need an owned copy only once. If that function was called, then this
|
||||||
/// will always return an empty slice.
|
/// will always return an empty slice.
|
||||||
#[must_use]
|
|
||||||
pub fn frontmatter(&self) -> &[Event<'a>] {
|
pub fn frontmatter(&self) -> &[Event<'a>] {
|
||||||
&self.frontmatter
|
&self.frontmatter
|
||||||
}
|
}
|
||||||
|
@ -543,7 +544,6 @@ impl<'a> Parser<'a> {
|
||||||
/// Returns the parsed sections from the parser. Consider
|
/// Returns the parsed sections from the parser. Consider
|
||||||
/// [`Parser::take_sections`] if you need an owned copy only once. If that
|
/// [`Parser::take_sections`] if you need an owned copy only once. If that
|
||||||
/// function was called, then this will always return an empty slice.
|
/// function was called, then this will always return an empty slice.
|
||||||
#[must_use]
|
|
||||||
pub fn sections(&self) -> &[ParsedSection<'a>] {
|
pub fn sections(&self) -> &[ParsedSection<'a>] {
|
||||||
&self.sections
|
&self.sections
|
||||||
}
|
}
|
||||||
|
@ -558,7 +558,6 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes the parser to produce a Vec of Events.
|
/// Consumes the parser to produce a Vec of Events.
|
||||||
#[must_use]
|
|
||||||
pub fn into_vec(self) -> Vec<Event<'a>> {
|
pub fn into_vec(self) -> Vec<Event<'a>> {
|
||||||
self.into_iter().collect()
|
self.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
@ -1001,7 +1000,7 @@ fn take_newline(i: &[u8]) -> IResult<&[u8], (&str, usize)> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod comments {
|
mod comments {
|
||||||
use super::comment;
|
use super::*;
|
||||||
use crate::test_util::{comment as parsed_comment, fully_consumed};
|
use crate::test_util::{comment as parsed_comment, fully_consumed};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1031,7 +1030,7 @@ mod comments {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod section_headers {
|
mod section_headers {
|
||||||
use super::section_header;
|
use super::*;
|
||||||
use crate::test_util::{fully_consumed, section_header as parsed_section_header};
|
use crate::test_util::{fully_consumed, section_header as parsed_section_header};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1103,7 +1102,7 @@ mod section_headers {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod config_name {
|
mod config_name {
|
||||||
use super::config_name;
|
use super::*;
|
||||||
use crate::test_util::fully_consumed;
|
use crate::test_util::fully_consumed;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1125,7 +1124,7 @@ mod config_name {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod section_body {
|
mod section_body {
|
||||||
use super::{section_body, Event, ParserNode};
|
use super::*;
|
||||||
use crate::test_util::{name_event, value_event, whitespace_event};
|
use crate::test_util::{name_event, value_event, whitespace_event};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1159,7 +1158,7 @@ mod section_body {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod value_no_continuation {
|
mod value_no_continuation {
|
||||||
use super::value_impl;
|
use super::*;
|
||||||
use crate::test_util::value_event;
|
use crate::test_util::value_event;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1265,7 +1264,7 @@ mod value_no_continuation {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod value_continuation {
|
mod value_continuation {
|
||||||
use super::value_impl;
|
use super::*;
|
||||||
use crate::test_util::{newline_event, value_done_event, value_not_done_event};
|
use crate::test_util::{newline_event, value_done_event, value_not_done_event};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1325,7 +1324,10 @@ mod value_continuation {
|
||||||
#[test]
|
#[test]
|
||||||
fn quote_split_over_two_lines_with_leftover_comment() {
|
fn quote_split_over_two_lines_with_leftover_comment() {
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
assert_eq!(value_impl(b"\"\\\n;\";a", &mut events).unwrap().0, b";a");
|
assert_eq!(
|
||||||
|
value_impl(b"\"\\\n;\";a", &mut events).unwrap().0,
|
||||||
|
";a".as_bytes()
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
events,
|
events,
|
||||||
vec![
|
vec![
|
||||||
|
@ -1339,7 +1341,7 @@ mod value_continuation {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod section {
|
mod section {
|
||||||
use super::{section, Event, ParsedSection, ParserNode};
|
use super::*;
|
||||||
use crate::test_util::{
|
use crate::test_util::{
|
||||||
comment_event, fully_consumed, name_event, newline_event,
|
comment_event, fully_consumed, name_event, newline_event,
|
||||||
section_header as parsed_section_header, value_done_event, value_event,
|
section_header as parsed_section_header, value_done_event, value_event,
|
||||||
|
@ -1539,7 +1541,7 @@ mod section {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod error {
|
mod error {
|
||||||
use super::parse_from_str;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_no_is_one_indexed() {
|
fn line_no_is_one_indexed() {
|
||||||
|
|
|
@ -59,7 +59,6 @@ use std::str::FromStr;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`parser`]: crate::parser::Parser
|
/// [`parser`]: crate::parser::Parser
|
||||||
#[must_use]
|
|
||||||
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||||
let size = input.len();
|
let size = input.len();
|
||||||
if &*input == b"\"\"" {
|
if &*input == b"\"\"" {
|
||||||
|
@ -121,21 +120,18 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||||
|
|
||||||
/// `&[u8]` variant of [`normalize_cow`].
|
/// `&[u8]` variant of [`normalize_cow`].
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
pub fn normalize_bytes(input: &[u8]) -> Cow<'_, [u8]> {
|
pub fn normalize_bytes(input: &[u8]) -> Cow<'_, [u8]> {
|
||||||
normalize_cow(Cow::Borrowed(input))
|
normalize_cow(Cow::Borrowed(input))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Vec[u8]` variant of [`normalize_cow`].
|
/// `Vec[u8]` variant of [`normalize_cow`].
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
pub fn normalize_vec(input: Vec<u8>) -> Cow<'static, [u8]> {
|
pub fn normalize_vec(input: Vec<u8>) -> Cow<'static, [u8]> {
|
||||||
normalize_cow(Cow::Owned(input))
|
normalize_cow(Cow::Owned(input))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`str`] variant of [`normalize_cow`].
|
/// [`str`] variant of [`normalize_cow`].
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
pub fn normalize_str(input: &str) -> Cow<'_, [u8]> {
|
pub fn normalize_str(input: &str) -> Cow<'_, [u8]> {
|
||||||
normalize_bytes(input.as_bytes())
|
normalize_bytes(input.as_bytes())
|
||||||
}
|
}
|
||||||
|
@ -154,7 +150,6 @@ pub enum Value<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Value<'_> {
|
impl Value<'_> {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -266,12 +261,10 @@ pub enum Boolean<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Boolean<'_> {
|
impl Boolean<'_> {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn as_bytes(&self) -> &[u8] {
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -507,7 +500,6 @@ pub struct Integer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Integer {
|
impl Integer {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -618,7 +610,6 @@ pub enum IntegerSuffix {
|
||||||
|
|
||||||
impl IntegerSuffix {
|
impl IntegerSuffix {
|
||||||
/// Returns the number of bits that the suffix shifts left by.
|
/// Returns the number of bits that the suffix shifts left by.
|
||||||
#[must_use]
|
|
||||||
pub const fn bitwise_offset(self) -> usize {
|
pub const fn bitwise_offset(self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
Self::Kibi => 10,
|
Self::Kibi => 10,
|
||||||
|
@ -699,7 +690,6 @@ pub struct Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
#[must_use]
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
pub fn to_vec(&self) -> Vec<u8> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -1128,7 +1118,7 @@ mod normalize {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod boolean {
|
mod boolean {
|
||||||
use super::{Boolean, TrueVariant, TryFrom};
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_str_false() {
|
fn from_str_false() {
|
||||||
|
@ -1181,7 +1171,7 @@ mod boolean {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod integer {
|
mod integer {
|
||||||
use super::{FromStr, Integer, IntegerSuffix};
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_str_no_suffix() {
|
fn from_str_no_suffix() {
|
||||||
|
|
|
@ -13,12 +13,12 @@ pub fn section_header(
|
||||||
name: &str,
|
name: &str,
|
||||||
subsection: impl Into<Option<(&'static str, &'static str)>>,
|
subsection: impl Into<Option<(&'static str, &'static str)>>,
|
||||||
) -> ParsedSectionHeader<'_> {
|
) -> ParsedSectionHeader<'_> {
|
||||||
let name = Cow::Borrowed(name);
|
let name = Cow::Borrowed(name.into());
|
||||||
if let Some((separator, subsection_name)) = subsection.into() {
|
if let Some((separator, subsection_name)) = subsection.into() {
|
||||||
ParsedSectionHeader {
|
ParsedSectionHeader {
|
||||||
name,
|
name,
|
||||||
separator: Some(Cow::Borrowed(separator)),
|
separator: Some(Cow::Borrowed(separator.into())),
|
||||||
subsection_name: Some(Cow::Borrowed(subsection_name)),
|
subsection_name: Some(Cow::Borrowed(subsection_name.into())),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ParsedSectionHeader {
|
ParsedSectionHeader {
|
||||||
|
@ -30,7 +30,7 @@ pub fn section_header(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(name: &'static str) -> Event<'static> {
|
fn name(name: &'static str) -> Event<'static> {
|
||||||
Event::Key(Cow::Borrowed(name))
|
Event::Key(Cow::Borrowed(name.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value(value: &'static str) -> Event<'static> {
|
fn value(value: &'static str) -> Event<'static> {
|
||||||
|
@ -42,11 +42,11 @@ fn newline() -> Event<'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn newline_custom(value: &'static str) -> Event<'static> {
|
fn newline_custom(value: &'static str) -> Event<'static> {
|
||||||
Event::Newline(Cow::Borrowed(value))
|
Event::Newline(Cow::Borrowed(value.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn whitespace(value: &'static str) -> Event<'static> {
|
fn whitespace(value: &'static str) -> Event<'static> {
|
||||||
Event::Whitespace(Cow::Borrowed(value))
|
Event::Whitespace(Cow::Borrowed(value.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn separator() -> Event<'static> {
|
fn separator() -> Event<'static> {
|
||||||
|
|
Reference in a new issue