Compare commits

..

No commits in common. "7c29e44f20e58d48eb9ef456b37652ecb8ab0729" and "6ce2c1d89de4066faa91c0e40df566bfa200af96" have entirely different histories.

5 changed files with 35 additions and 45 deletions

View file

@ -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`].
pub struct MutableMultiValue<'borrow, 'lookup, '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.
#[inline]
#[must_use]
pub fn len(&self) -> usize {
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
/// was deleted but not set with a new value.
#[inline]
#[must_use]
pub fn is_empty(&self) -> bool {
self.indices_and_sizes.is_empty()
}
@ -1133,8 +1131,8 @@ impl Display for GitConfig<'_> {
#[cfg(test)]
mod from_parser {
use super::{Cow, Event, GitConfig, HashMap, LookupTreeNode, SectionId, TryFrom};
use crate::test_util::{name_event, newline_event, section_header, value_event};
use super::*;
use crate::test_util::*;
#[test]
fn parse_empty() {
@ -1333,7 +1331,7 @@ mod from_parser {
#[cfg(test)]
mod get_raw_value {
use super::{Cow, GitConfig, GitConfigError, TryFrom};
use super::*;
#[test]
fn single_section() {
@ -1409,7 +1407,7 @@ mod get_raw_value {
#[cfg(test)]
mod get_value {
use super::{Cow, GitConfig, TryFrom};
use super::*;
use crate::values::{Boolean, TrueVariant, Value};
use std::error::Error;
@ -1428,7 +1426,7 @@ mod get_value {
#[cfg(test)]
mod get_raw_multi_value {
use super::{Cow, GitConfig, GitConfigError, TryFrom};
use super::*;
#[test]
fn single_value_is_identical_to_single_value_query() {
@ -1517,7 +1515,7 @@ mod get_raw_multi_value {
#[cfg(test)]
mod display {
use super::{GitConfig, TryFrom};
use super::*;
#[test]
fn can_reconstruct_empty_config() {

View file

@ -1,7 +1,7 @@
#![forbid(unsafe_code)]
// #![deny(missing_docs)]
#![warn(clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(clippy::shadow_unrelated)]
#![allow(clippy::must_use_candidate, clippy::shadow_unrelated)]
//! # `git_config`
//!

View file

@ -69,7 +69,6 @@ pub enum Event<'a> {
}
impl Event<'_> {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
@ -97,7 +96,13 @@ impl Display for Event<'_> {
impl Into<Vec<u8>> for Event<'_> {
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<'_> {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
@ -245,13 +249,11 @@ pub struct Error<'a> {
impl Error<'_> {
/// The one-indexed line number where the error occurred. This is determined
/// by the number of newlines that were successfully parsed.
#[must_use]
pub const fn line_number(&self) -> usize {
self.line_number + 1
}
/// The remaining data that was left unparsed.
#[must_use]
pub const fn remaining_data(&self) -> &[u8] {
self.parsed_until
}
@ -525,7 +527,6 @@ impl<'a> Parser<'a> {
/// a section) from the parser. Consider [`Parser::take_frontmatter`] if
/// you need an owned copy only once. If that function was called, then this
/// will always return an empty slice.
#[must_use]
pub fn frontmatter(&self) -> &[Event<'a>] {
&self.frontmatter
}
@ -543,7 +544,6 @@ impl<'a> Parser<'a> {
/// Returns the parsed sections from the parser. Consider
/// [`Parser::take_sections`] if you need an owned copy only once. If that
/// function was called, then this will always return an empty slice.
#[must_use]
pub fn sections(&self) -> &[ParsedSection<'a>] {
&self.sections
}
@ -558,7 +558,6 @@ impl<'a> Parser<'a> {
}
/// Consumes the parser to produce a Vec of Events.
#[must_use]
pub fn into_vec(self) -> Vec<Event<'a>> {
self.into_iter().collect()
}
@ -1001,7 +1000,7 @@ fn take_newline(i: &[u8]) -> IResult<&[u8], (&str, usize)> {
#[cfg(test)]
mod comments {
use super::comment;
use super::*;
use crate::test_util::{comment as parsed_comment, fully_consumed};
#[test]
@ -1031,7 +1030,7 @@ mod comments {
#[cfg(test)]
mod section_headers {
use super::section_header;
use super::*;
use crate::test_util::{fully_consumed, section_header as parsed_section_header};
#[test]
@ -1103,7 +1102,7 @@ mod section_headers {
#[cfg(test)]
mod config_name {
use super::config_name;
use super::*;
use crate::test_util::fully_consumed;
#[test]
@ -1125,7 +1124,7 @@ mod config_name {
#[cfg(test)]
mod section_body {
use super::{section_body, Event, ParserNode};
use super::*;
use crate::test_util::{name_event, value_event, whitespace_event};
#[test]
@ -1159,7 +1158,7 @@ mod section_body {
#[cfg(test)]
mod value_no_continuation {
use super::value_impl;
use super::*;
use crate::test_util::value_event;
#[test]
@ -1265,7 +1264,7 @@ mod value_no_continuation {
#[cfg(test)]
mod value_continuation {
use super::value_impl;
use super::*;
use crate::test_util::{newline_event, value_done_event, value_not_done_event};
#[test]
@ -1325,7 +1324,10 @@ mod value_continuation {
#[test]
fn quote_split_over_two_lines_with_leftover_comment() {
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!(
events,
vec![
@ -1339,7 +1341,7 @@ mod value_continuation {
#[cfg(test)]
mod section {
use super::{section, Event, ParsedSection, ParserNode};
use super::*;
use crate::test_util::{
comment_event, fully_consumed, name_event, newline_event,
section_header as parsed_section_header, value_done_event, value_event,
@ -1539,7 +1541,7 @@ mod section {
#[cfg(test)]
mod error {
use super::parse_from_str;
use super::*;
#[test]
fn line_no_is_one_indexed() {

View file

@ -59,7 +59,6 @@ use std::str::FromStr;
/// ```
///
/// [`parser`]: crate::parser::Parser
#[must_use]
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
let size = input.len();
if &*input == b"\"\"" {
@ -121,21 +120,18 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
/// `&[u8]` variant of [`normalize_cow`].
#[inline]
#[must_use]
pub fn normalize_bytes(input: &[u8]) -> Cow<'_, [u8]> {
normalize_cow(Cow::Borrowed(input))
}
/// `Vec[u8]` variant of [`normalize_cow`].
#[inline]
#[must_use]
pub fn normalize_vec(input: Vec<u8>) -> Cow<'static, [u8]> {
normalize_cow(Cow::Owned(input))
}
/// [`str`] variant of [`normalize_cow`].
#[inline]
#[must_use]
pub fn normalize_str(input: &str) -> Cow<'_, [u8]> {
normalize_bytes(input.as_bytes())
}
@ -154,7 +150,6 @@ pub enum Value<'a> {
}
impl Value<'_> {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
@ -266,12 +261,10 @@ pub enum Boolean<'a> {
}
impl Boolean<'_> {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
self.into()
}
@ -507,7 +500,6 @@ pub struct Integer {
}
impl Integer {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
@ -618,7 +610,6 @@ pub enum IntegerSuffix {
impl IntegerSuffix {
/// Returns the number of bits that the suffix shifts left by.
#[must_use]
pub const fn bitwise_offset(self) -> usize {
match self {
Self::Kibi => 10,
@ -699,7 +690,6 @@ pub struct Color {
}
impl Color {
#[must_use]
pub fn to_vec(&self) -> Vec<u8> {
self.into()
}
@ -1128,7 +1118,7 @@ mod normalize {
#[cfg(test)]
mod boolean {
use super::{Boolean, TrueVariant, TryFrom};
use super::*;
#[test]
fn from_str_false() {
@ -1181,7 +1171,7 @@ mod boolean {
#[cfg(test)]
mod integer {
use super::{FromStr, Integer, IntegerSuffix};
use super::*;
#[test]
fn from_str_no_suffix() {

View file

@ -13,12 +13,12 @@ pub fn section_header(
name: &str,
subsection: impl Into<Option<(&'static str, &'static str)>>,
) -> ParsedSectionHeader<'_> {
let name = Cow::Borrowed(name);
let name = Cow::Borrowed(name.into());
if let Some((separator, subsection_name)) = subsection.into() {
ParsedSectionHeader {
name,
separator: Some(Cow::Borrowed(separator)),
subsection_name: Some(Cow::Borrowed(subsection_name)),
separator: Some(Cow::Borrowed(separator.into())),
subsection_name: Some(Cow::Borrowed(subsection_name.into())),
}
} else {
ParsedSectionHeader {
@ -30,7 +30,7 @@ pub fn section_header(
}
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> {
@ -42,11 +42,11 @@ fn newline() -> 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> {
Event::Whitespace(Cow::Borrowed(value))
Event::Whitespace(Cow::Borrowed(value.into()))
}
fn separator() -> Event<'static> {