Add missing_docs
warning.
This commit is contained in:
parent
8247f481c7
commit
ccd7b6e718
7 changed files with 83 additions and 13 deletions
|
@ -5,6 +5,7 @@ before_commit:
|
||||||
cargo build --all-targets
|
cargo build --all-targets
|
||||||
cargo test
|
cargo test
|
||||||
cargo test --release
|
cargo test --release
|
||||||
|
cargo test --doc
|
||||||
cargo build --profile=release-lto --package gen_large_yaml --bin gen_large_yaml --manifest-path tools/gen_large_yaml/Cargo.toml
|
cargo build --profile=release-lto --package gen_large_yaml --bin gen_large_yaml --manifest-path tools/gen_large_yaml/Cargo.toml
|
||||||
|
|
||||||
ethi_bench:
|
ethi_bench:
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
|
//! YAML serialization helpers.
|
||||||
|
|
||||||
use crate::char_traits;
|
use crate::char_traits;
|
||||||
use crate::yaml::{Hash, Yaml};
|
use crate::yaml::{Hash, Yaml};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
|
|
||||||
|
/// An error when emitting YAML.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum EmitError {
|
pub enum EmitError {
|
||||||
|
/// A formatting error.
|
||||||
FmtError(fmt::Error),
|
FmtError(fmt::Error),
|
||||||
BadHashmapKey,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for EmitError {
|
impl Error for EmitError {
|
||||||
|
@ -20,7 +23,6 @@ impl Display for EmitError {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
EmitError::FmtError(ref err) => Display::fmt(err, formatter),
|
EmitError::FmtError(ref err) => Display::fmt(err, formatter),
|
||||||
EmitError::BadHashmapKey => formatter.write_str("bad hashmap key"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +33,20 @@ impl From<fmt::Error> for EmitError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The YAML serializer.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use yaml_rust2::{YamlLoader, YamlEmitter};
|
||||||
|
/// let input_string = "a: b\nc: d";
|
||||||
|
/// let yaml = YamlLoader::load_from_str(input_string).unwrap();
|
||||||
|
///
|
||||||
|
/// let mut output = String::new();
|
||||||
|
/// YamlEmitter::new(&mut output).dump(&yaml[0]).unwrap();
|
||||||
|
///
|
||||||
|
/// assert_eq!(output, r#"---
|
||||||
|
/// a: b
|
||||||
|
/// c: d"#);
|
||||||
|
/// ```
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
pub struct YamlEmitter<'a> {
|
pub struct YamlEmitter<'a> {
|
||||||
writer: &'a mut dyn fmt::Write,
|
writer: &'a mut dyn fmt::Write,
|
||||||
|
@ -40,6 +56,7 @@ pub struct YamlEmitter<'a> {
|
||||||
multiline_strings: bool,
|
multiline_strings: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A convenience alias for emitter functions that may fail without returning a value.
|
||||||
pub type EmitResult = Result<(), EmitError>;
|
pub type EmitResult = Result<(), EmitError>;
|
||||||
|
|
||||||
// from serialize::json
|
// from serialize::json
|
||||||
|
@ -106,6 +123,7 @@ fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> Result<(), fmt::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> YamlEmitter<'a> {
|
impl<'a> YamlEmitter<'a> {
|
||||||
|
/// Create a nwe emitter serializing into `writer`.
|
||||||
pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter {
|
pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter {
|
||||||
YamlEmitter {
|
YamlEmitter {
|
||||||
writer,
|
writer,
|
||||||
|
|
|
@ -30,14 +30,7 @@
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![warn(clippy::pedantic)]
|
#![warn(missing_docs, clippy::pedantic)]
|
||||||
#![allow(
|
|
||||||
clippy::match_same_arms,
|
|
||||||
clippy::should_implement_trait,
|
|
||||||
clippy::missing_errors_doc,
|
|
||||||
clippy::missing_panics_doc,
|
|
||||||
clippy::redundant_else
|
|
||||||
)]
|
|
||||||
|
|
||||||
extern crate hashlink;
|
extern crate hashlink;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
//! Home to the YAML Parser.
|
||||||
|
//!
|
||||||
|
//! The parser takes input from the [`crate::scanner::Scanner`], performs final checks for YAML
|
||||||
|
//! compliance, and emits a stream of tokens that can be used by the [`crate::YamlLoader`] to
|
||||||
|
//! construct the [`crate::Yaml`] object.
|
||||||
|
|
||||||
use crate::scanner::{Marker, ScanError, Scanner, TScalarStyle, Token, TokenType};
|
use crate::scanner::{Marker, ScanError, Scanner, TScalarStyle, Token, TokenType};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -53,19 +59,23 @@ pub enum Event {
|
||||||
),
|
),
|
||||||
/// Value, style, anchor_id, tag
|
/// Value, style, anchor_id, tag
|
||||||
Scalar(String, TScalarStyle, usize, Option<Tag>),
|
Scalar(String, TScalarStyle, usize, Option<Tag>),
|
||||||
|
/// The start of a YAML sequence (array).
|
||||||
SequenceStart(
|
SequenceStart(
|
||||||
/// The anchor ID of the start of the squence.
|
/// The anchor ID of the start of the squence.
|
||||||
usize,
|
usize,
|
||||||
/// An optional tag
|
/// An optional tag
|
||||||
Option<Tag>,
|
Option<Tag>,
|
||||||
),
|
),
|
||||||
|
/// The end of a YAML sequence (array).
|
||||||
SequenceEnd,
|
SequenceEnd,
|
||||||
|
/// The start of a YAML mapping (object, hash).
|
||||||
MappingStart(
|
MappingStart(
|
||||||
/// The anchor ID of the start of the mapping.
|
/// The anchor ID of the start of the mapping.
|
||||||
usize,
|
usize,
|
||||||
/// An optional tag
|
/// An optional tag
|
||||||
Option<Tag>,
|
Option<Tag>,
|
||||||
),
|
),
|
||||||
|
/// The end of a YAML mapping (object, hash).
|
||||||
MappingEnd,
|
MappingEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +205,7 @@ impl<R: EventReceiver> MarkedEventReceiver for R {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A convenience alias for a `Result` of a parser event.
|
||||||
pub type ParseResult = Result<(Event, Marker), ScanError>;
|
pub type ParseResult = Result<(Event, Marker), ScanError>;
|
||||||
|
|
||||||
impl<T: Iterator<Item = char>> Parser<T> {
|
impl<T: Iterator<Item = char>> Parser<T> {
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
//! Home to the YAML Scanner.
|
||||||
|
//!
|
||||||
|
//! The scanner is the lowest-level parsing utility. It is the lexer / tokenizer, reading input a
|
||||||
|
//! character at a time and emitting tokens that can later be interpreted by the [`crate::parser`]
|
||||||
|
//! to check for more context and validity.
|
||||||
|
//!
|
||||||
|
//! Due to the grammar of YAML, the scanner has to have some context and is not error-free.
|
||||||
|
|
||||||
#![allow(clippy::cast_possible_wrap)]
|
#![allow(clippy::cast_possible_wrap)]
|
||||||
#![allow(clippy::cast_sign_loss)]
|
#![allow(clippy::cast_sign_loss)]
|
||||||
|
|
||||||
|
@ -10,19 +18,26 @@ use crate::char_traits::{
|
||||||
is_flow, is_hex, is_tag_char, is_uri_char, is_z,
|
is_flow, is_hex, is_tag_char, is_uri_char, is_z,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The encoding of the input. Currently, only UTF-8 is supported.
|
||||||
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
||||||
pub enum TEncoding {
|
pub enum TEncoding {
|
||||||
|
/// UTF-8 encoding.
|
||||||
Utf8,
|
Utf8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The style as which the scalar was written in the YAML document.
|
||||||
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
||||||
pub enum TScalarStyle {
|
pub enum TScalarStyle {
|
||||||
Any,
|
/// A YAML plain scalar.
|
||||||
Plain,
|
Plain,
|
||||||
|
/// A YAML single quoted scalar.
|
||||||
SingleQuoted,
|
SingleQuoted,
|
||||||
|
/// A YAML double quoted scalar.
|
||||||
DoubleQuoted,
|
DoubleQuoted,
|
||||||
|
|
||||||
|
/// A YAML literal block (`|` block).
|
||||||
Literal,
|
Literal,
|
||||||
|
/// A YAML folded block (`>` block).
|
||||||
Folded,
|
Folded,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,17 +135,18 @@ impl fmt::Display for ScanError {
|
||||||
/// The contents of a scanner token.
|
/// The contents of a scanner token.
|
||||||
#[derive(Clone, PartialEq, Debug, Eq)]
|
#[derive(Clone, PartialEq, Debug, Eq)]
|
||||||
pub enum TokenType {
|
pub enum TokenType {
|
||||||
NoToken,
|
|
||||||
/// The start of the stream. Sent first, before even [`DocumentStart`].
|
/// The start of the stream. Sent first, before even [`DocumentStart`].
|
||||||
StreamStart(TEncoding),
|
StreamStart(TEncoding),
|
||||||
/// The end of the stream, EOF.
|
/// The end of the stream, EOF.
|
||||||
StreamEnd,
|
StreamEnd,
|
||||||
|
/// A YAML version directive.
|
||||||
VersionDirective(
|
VersionDirective(
|
||||||
/// Major
|
/// Major
|
||||||
u32,
|
u32,
|
||||||
/// Minor
|
/// Minor
|
||||||
u32,
|
u32,
|
||||||
),
|
),
|
||||||
|
/// A YAML tag directive (e.g.: `!!str`, `!foo!bar`, ...).
|
||||||
TagDirective(
|
TagDirective(
|
||||||
/// Handle
|
/// Handle
|
||||||
String,
|
String,
|
||||||
|
@ -394,6 +410,7 @@ impl<T: Iterator<Item = char>> Iterator for Scanner<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A convenience alias for scanner functions that may fail without returning a value.
|
||||||
pub type ScanResult = Result<(), ScanError>;
|
pub type ScanResult = Result<(), ScanError>;
|
||||||
|
|
||||||
impl<T: Iterator<Item = char>> Scanner<T> {
|
impl<T: Iterator<Item = char>> Scanner<T> {
|
||||||
|
@ -532,16 +549,19 @@ impl<T: Iterator<Item = char>> Scanner<T> {
|
||||||
self.buffer[0] == c
|
self.buffer[0] == c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return whether the [`TokenType::StreamStart`] event has been emitted.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn stream_started(&self) -> bool {
|
pub fn stream_started(&self) -> bool {
|
||||||
self.stream_start_produced
|
self.stream_start_produced
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return whether the [`TokenType::StreamEnd`] event has been emitted.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn stream_ended(&self) -> bool {
|
pub fn stream_ended(&self) -> bool {
|
||||||
self.stream_end_produced
|
self.stream_end_produced
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current position in the input stream.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mark(&self) -> Marker {
|
pub fn mark(&self) -> Marker {
|
||||||
self.mark
|
self.mark
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! YAML objects manipulation utilities.
|
||||||
|
|
||||||
#![allow(clippy::module_name_repetitions)]
|
#![allow(clippy::module_name_repetitions)]
|
||||||
|
|
||||||
use std::{collections::BTreeMap, convert::TryFrom, mem, ops::Index};
|
use std::{collections::BTreeMap, convert::TryFrom, mem, ops::Index};
|
||||||
|
@ -50,7 +52,9 @@ pub enum Yaml {
|
||||||
BadValue,
|
BadValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The type contained in the `Yaml::Array` variant. This corresponds to YAML sequences.
|
||||||
pub type Array = Vec<Yaml>;
|
pub type Array = Vec<Yaml>;
|
||||||
|
/// The type contained in the `Yaml::Hash` variant. This corresponds to YAML mappings.
|
||||||
pub type Hash = LinkedHashMap<Yaml, Yaml>;
|
pub type Hash = LinkedHashMap<Yaml, Yaml>;
|
||||||
|
|
||||||
// parse f64 as Core schema
|
// parse f64 as Core schema
|
||||||
|
@ -69,6 +73,7 @@ fn parse_f64(v: &str) -> Option<f64> {
|
||||||
/// See [`YamlLoader::load_from_str`].
|
/// See [`YamlLoader::load_from_str`].
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct YamlLoader {
|
pub struct YamlLoader {
|
||||||
|
/// The different YAML documents that are loaded.
|
||||||
docs: Vec<Yaml>,
|
docs: Vec<Yaml>,
|
||||||
// states
|
// states
|
||||||
// (current node, anchor_id) tuple
|
// (current node, anchor_id) tuple
|
||||||
|
@ -161,10 +166,14 @@ impl MarkedEventReceiver for YamlLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An error that happened when loading a YAML document.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LoadError {
|
pub enum LoadError {
|
||||||
|
/// An I/O error.
|
||||||
IO(std::io::Error),
|
IO(std::io::Error),
|
||||||
|
/// An error within the scanner. This indicates a malformed YAML input.
|
||||||
Scan(ScanError),
|
Scan(ScanError),
|
||||||
|
/// A decoding error (e.g.: Invalid UTF_8).
|
||||||
Decode(std::borrow::Cow<'static, str>),
|
Decode(std::borrow::Cow<'static, str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +260,7 @@ pub struct YamlDecoder<T: std::io::Read> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: std::io::Read> YamlDecoder<T> {
|
impl<T: std::io::Read> YamlDecoder<T> {
|
||||||
|
/// Create a `YamlDecoder` decoding the given source.
|
||||||
pub fn read(source: T) -> YamlDecoder<T> {
|
pub fn read(source: T) -> YamlDecoder<T> {
|
||||||
YamlDecoder {
|
YamlDecoder {
|
||||||
source,
|
source,
|
||||||
|
@ -258,11 +268,14 @@ impl<T: std::io::Read> YamlDecoder<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the behavior of the decoder when the encoding is invalid.
|
||||||
pub fn encoding_trap(&mut self, trap: encoding::types::DecoderTrap) -> &mut Self {
|
pub fn encoding_trap(&mut self, trap: encoding::types::DecoderTrap) -> &mut Self {
|
||||||
self.trap = trap;
|
self.trap = trap;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run the decode operation with the source and trap the `YamlDecoder` was built with.
|
||||||
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns `LoadError` when decoding fails.
|
/// Returns `LoadError` when decoding fails.
|
||||||
pub fn decode(&mut self) -> Result<Vec<Yaml>, LoadError> {
|
pub fn decode(&mut self) -> Result<Vec<Yaml>, LoadError> {
|
||||||
|
@ -301,6 +314,11 @@ fn detect_utf16_endianness(b: &[u8]) -> encoding::types::EncodingRef {
|
||||||
|
|
||||||
macro_rules! define_as (
|
macro_rules! define_as (
|
||||||
($name:ident, $t:ident, $yt:ident) => (
|
($name:ident, $t:ident, $yt:ident) => (
|
||||||
|
/// Get a copy of the inner object in the YAML enum if it is a `$t`.
|
||||||
|
///
|
||||||
|
/// # Return
|
||||||
|
/// If the variant of `self` is `Yaml::$yt`, return `Some($t)` with a copy of the `$t` contained.
|
||||||
|
/// Otherwise, return `None`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn $name(&self) -> Option<$t> {
|
pub fn $name(&self) -> Option<$t> {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -313,6 +331,11 @@ pub fn $name(&self) -> Option<$t> {
|
||||||
|
|
||||||
macro_rules! define_as_ref (
|
macro_rules! define_as_ref (
|
||||||
($name:ident, $t:ty, $yt:ident) => (
|
($name:ident, $t:ty, $yt:ident) => (
|
||||||
|
/// Get a reference to the inner object in the YAML enum if it is a `$t`.
|
||||||
|
///
|
||||||
|
/// # Return
|
||||||
|
/// If the variant of `self` is `Yaml::$yt`, return `Some(&$t)` with the `$t` contained. Otherwise,
|
||||||
|
/// return `None`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn $name(&self) -> Option<$t> {
|
pub fn $name(&self) -> Option<$t> {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -325,6 +348,11 @@ pub fn $name(&self) -> Option<$t> {
|
||||||
|
|
||||||
macro_rules! define_into (
|
macro_rules! define_into (
|
||||||
($name:ident, $t:ty, $yt:ident) => (
|
($name:ident, $t:ty, $yt:ident) => (
|
||||||
|
/// Get the inner object in the YAML enum if it is a `$t`.
|
||||||
|
///
|
||||||
|
/// # Return
|
||||||
|
/// If the variant of `self` is `Yaml::$yt`, return `Some($t)` with the `$t` contained. Otherwise,
|
||||||
|
/// return `None`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn $name(self) -> Option<$t> {
|
pub fn $name(self) -> Option<$t> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -163,7 +163,6 @@ impl EventReceiver for EventReporter {
|
||||||
TScalarStyle::DoubleQuoted => r#"""#,
|
TScalarStyle::DoubleQuoted => r#"""#,
|
||||||
TScalarStyle::Literal => "|",
|
TScalarStyle::Literal => "|",
|
||||||
TScalarStyle::Folded => ">",
|
TScalarStyle::Folded => ">",
|
||||||
TScalarStyle::Any => unreachable!(),
|
|
||||||
};
|
};
|
||||||
format!(
|
format!(
|
||||||
"=VAL{}{} {}{}",
|
"=VAL{}{} {}{}",
|
||||||
|
|
Loading…
Reference in a new issue