11// SPDX-License-Identifier: GPL-3.0-or-later
22
3- //! This module is responsible for declaring the file formats this project
4- //! is using. The following formats are declared:
3+ //! This module declares the file formats used by this project.
4+ //! The following formats are declared:
55//!
6- //! - The JSON compilation database format. Declared by the Clang project.
7- //! - The semantic database format. (Internal format of this project.)
8- //! - The execution event database format. (Internal format of this project.)
6+ //! - The JSON compilation database format, as declared by the Clang project.
7+ //! - The semantic database format (internal format of this project).
8+ //! - The execution event database format (internal format of this project.)
99
1010use super :: json;
1111use crate :: { intercept, semantic, semantic:: clang} ;
1212use serde_json:: de:: IoRead ;
1313use serde_json:: StreamDeserializer ;
1414use thiserror:: Error ;
1515
16- /// The trait represents a file format that can be written to and read from.
16+ /// Represents errors that can occur while working with file formats.
17+ #[ derive( Debug , Error ) ]
18+ pub enum SerializationError {
19+ #[ error( "Generic IO error: {0}" ) ]
20+ Io ( #[ from] std:: io:: Error ) ,
21+ #[ error( "Format syntax error: {0}" ) ]
22+ Syntax ( #[ from] serde_json:: Error ) ,
23+ #[ error( "Format semantic error: {0}" ) ]
24+ Semantic ( #[ from] clang:: EntryError ) ,
25+ }
26+
27+ /// A trait representing a file format that can be written to and read from.
1728///
18- /// The file format in this project is usually a sequence of values. This trait
19- /// provides a type-independent abstraction over the file format .
29+ /// File formats in this project are usually sequences of values. This trait
30+ /// provides a type-independent abstraction over file formats .
2031pub trait SerializationFormat < T > {
21- fn write ( _: impl std:: io:: Write , _: impl Iterator < Item = T > ) -> Result < ( ) , SerializationError > ;
32+ /// Writes an iterator of items to the specified writer.
33+ fn write (
34+ writer : impl std:: io:: Write ,
35+ items : impl Iterator < Item = T > ,
36+ ) -> Result < ( ) , SerializationError > ;
2237
23- fn read ( _: impl std:: io:: Read ) -> impl Iterator < Item = Result < T , SerializationError > > ;
38+ /// Reads items from the specified reader, returning an iterator of results.
39+ fn read ( reader : impl std:: io:: Read ) -> impl Iterator < Item = Result < T , SerializationError > > ;
2440
25- /// Reads the entries from the file and ignores any errors.
26- /// This is not always feasible, when the file format is strict.
41+ /// Reads entries from the file and ignores any errors.
42+ ///
43+ /// This is not always feasible when the file format is strict.
2744 fn read_and_ignore (
2845 reader : impl std:: io:: Read ,
2946 message_writer : impl Fn ( & str ) ,
@@ -38,17 +55,6 @@ pub trait SerializationFormat<T> {
3855 }
3956}
4057
41- /// Represents errors that can occur while working with file formats.
42- #[ derive( Debug , Error ) ]
43- pub enum SerializationError {
44- #[ error( "Generic IO error: {0}" ) ]
45- Io ( #[ from] std:: io:: Error ) ,
46- #[ error( "Format syntax error: {0}" ) ]
47- Syntax ( #[ from] serde_json:: Error ) ,
48- #[ error( "Format semantic error: {0}" ) ]
49- Semantic ( #[ from] clang:: EntryError ) ,
50- }
51-
5258/// The type represents a JSON compilation database format.
5359///
5460/// The format is a JSON array format, which is a sequence of JSON objects
@@ -102,9 +108,9 @@ pub struct JsonSemanticDatabase;
102108impl SerializationFormat < semantic:: Command > for JsonSemanticDatabase {
103109 fn write (
104110 writer : impl std:: io:: Write ,
105- entries : impl Iterator < Item = semantic:: Command > ,
111+ commands : impl Iterator < Item = semantic:: Command > ,
106112 ) -> Result < ( ) , SerializationError > {
107- json:: serialize_seq ( writer, entries ) . map_err ( SerializationError :: Syntax )
113+ json:: serialize_seq ( writer, commands ) . map_err ( SerializationError :: Syntax )
108114 }
109115 fn read (
110116 _: impl std:: io:: Read ,
0 commit comments