Skip to content

Commit

Permalink
cxx-qt-gen: enable missing_docs and fix missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Mar 1, 2024
1 parent b0a9700 commit 10677ce
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
11 changes: 10 additions & 1 deletion crates/cxx-qt-gen/src/generator/cpp/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

#[derive(PartialEq, Eq, Debug)]
/// A fragment of C++ code
pub enum CppFragment {
Pair { header: String, source: String },
/// A fragment which only both a header and a source
Pair {
/// The header of the fragment
header: String,
/// The source of the fragment
source: String,
},
/// A fragment which only has a header
Header(String),
/// A fragment which only has a source
Source(String),
}

Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/src/generator/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct GeneratedCppBlocks {
}

impl GeneratedCppBlocks {
/// Create a [GeneratedCppBlocks] from the given [Parser] object
pub fn from(parser: &Parser) -> Result<GeneratedCppBlocks> {
let mut includes = BTreeSet::new();

Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/src/generator/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct GeneratedRustBlocks {
}

impl GeneratedRustBlocks {
/// Create a [GeneratedRustBlocks] from the given [Parser] object
pub fn from(parser: &Parser) -> Result<GeneratedRustBlocks> {
let mut fragments = vec![];
fragments.extend(
Expand Down
9 changes: 7 additions & 2 deletions crates/cxx-qt-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// SPDX-FileContributor: Gerhard de Clercq <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#![deny(missing_docs)]

//! The cxx-qt-gen crate provides methods for generated C++ and Rust code from a TokenStream.
mod generator;
mod naming;
mod parser;
Expand All @@ -13,8 +18,8 @@ pub use generator::{
cpp::{fragment::CppFragment, GeneratedCppBlocks},
rust::GeneratedRustBlocks,
};
pub use parser::{qobject::QmlElementMetadata, Parser};
pub use syntax::{parse_qt_file, CxxQtItem};
pub use parser::Parser;
pub use syntax::{parse_qt_file, CxxQtFile, CxxQtItem};
pub use writer::{cpp::write_cpp, rust::write_rust};

pub use syn::{Error, Result};
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use syn::{
/// [syn::Item]'s that are not handled specially by CXX-Qt are passed through for CXX to process.
pub struct Parser {
/// The module which unknown (eg CXX) blocks are stored into
pub passthrough_module: ItemMod,
pub(crate) passthrough_module: ItemMod,
/// Any CXX-Qt data that needs generation later
pub cxx_qt_data: ParsedCxxQtData,
pub(crate) cxx_qt_data: ParsedCxxQtData,
/// all type names that were found in this module, including CXX types
pub type_names: TypeNames,
pub(crate) type_names: TypeNames,
/// The stem of the file that the CXX headers for this module will be generated into
pub cxx_file_stem: String,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ mod qtitem;
pub mod safety;
pub mod types;

pub use qtfile::parse_qt_file;
pub use qtfile::{parse_qt_file, CxxQtFile};
pub use qtitem::CxxQtItem;
4 changes: 4 additions & 0 deletions crates/cxx-qt-gen/src/syntax/qtfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use quote::{ToTokens, TokenStreamExt};
use syn::parse::{Parse, ParseStream};
use syn::{AttrStyle, Attribute, Result};

/// Representation of a CxxQtFile as Syn items
pub struct CxxQtFile {
/// A vector of [syn::Attribute] in the file
pub attrs: Vec<Attribute>,
/// A vector of [CxxQtItem] items in the file
pub items: Vec<CxxQtItem>,
}

Expand Down Expand Up @@ -40,6 +43,7 @@ impl ToTokens for CxxQtFile {
}
}

/// Parse the given [std::path::Path] into a [CxxQtFile]
pub fn parse_qt_file(path: impl AsRef<std::path::Path>) -> Result<CxxQtFile> {
let source = std::fs::read_to_string(path.as_ref()).unwrap_or_else(|err| {
// todo: fixme with a proper error propagation
Expand Down
3 changes: 1 addition & 2 deletions crates/cxx-qt-gen/src/syntax/qtitem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use syn::parse::{Parse, ParseStream};
use syn::{Attribute, Item, ItemMod, Result, Token, Visibility};

#[derive(Clone, PartialEq, Eq)]
// This warning is triggered when running clippy on crates that depend on cxx-qt-gen,
// but not when running clippy on cxx-qt-gen.
/// Representation of either a Syn Item, a CXX module, or a CXX-Qt module
pub enum CxxQtItem {
/// A normal syntax item that we pass through
Item(Item),
Expand Down

0 comments on commit 10677ce

Please sign in to comment.