pub(crate) fn write_category_mod<W: Write>(
    mut file: &mut W,
    category: Category,
    definitions: &[Definition],
    metadata: &Metadata,
    config: &Config,
) -> io::Result<()> {
    // Begin outermost mod
    match category {
        Category::Types => {
            write!(
                file,
                "\
                 /// This module contains all of the bare types, each\n\
                 /// represented by a `struct`. All of them implement\n\
                 /// [`Identifiable`], [`Serializable`] and [`Deserializable`].\n\
                 ///\n\
                 /// [`Identifiable`]: ../trait.Identifiable.html\n\
                 /// [`Serializable`]: ../trait.Serializable.html\n\
                 /// [`Deserializable`]: ../trait.Deserializable.html\n\
                 #[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]\n\
                 pub mod types {{\n\
                 "
            )?;
        }
        Category::Functions => {
            writeln!(
                file,
                "\
            /// This module contains all of the functions, each\n\
            /// represented by a `struct`. All of them implement\n\
            /// [`Identifiable`] and [`Serializable`].\n\
            ///\n\
            /// To find out the type that Telegram will return upon\n\
            /// invoking one of these requests, check out the associated\n\
            /// type in the corresponding [`RemoteCall`] trait impl.\n\
            ///\n\
            /// [`Identifiable`]: ../trait.Identifiable.html\n\
            /// [`Serializable`]: ../trait.Serializable.html\n\
            /// [`RemoteCall`]: trait.RemoteCall.html\n\
            #[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]\n\
            pub mod functions {{
            "
            )?;
        }
    }

    let grouped = grouper::group_by_ns(definitions, category);
    let mut sorted_keys: Vec<&String> = grouped.keys().collect();
    sorted_keys.sort();
    for key in sorted_keys.into_iter() {
        // Begin possibly inner mod
        let indent = if key.is_empty() {
            "    "
        } else {
            writeln!(file, "    #[allow(clippy::unreadable_literal)]")?;
            writeln!(file, "    pub mod {} {{", key)?;
            "        "
        };

        if category == Category::Types && config.impl_from_enum {
            // If all of the conversions are infallible this will be unused.
            // Don't bother checking this beforehand, just allow warnings.
            writeln!(file, "{}#[allow(unused_imports)]", indent)?;
            writeln!(file, "{}use std::convert::TryFrom;", indent)?;
        }

        for definition in grouped[key]
            .iter()
            .filter(|def| def.category == Category::Functions || !ignore_type(&def.ty))
        {
            write_definition(&mut file, indent, definition, metadata, config)?;
        }

        // End possibly inner mod
        if !key.is_empty() {
            writeln!(file, "    }}")?;
        }
    }

    // End outermost mod
    writeln!(file, "}}")
}
/// Write an entire module for the desired category.
Write an entire module for the desired category.
Write an entire module for the desired category .
pub(crate) fn write_category_mod<W: Write>(
    mut file: &mut W,
    category: Category,
    definitions: &[Definition],
    metadata: &Metadata,
    config: &Config,
) -> io::Result<()> {
    // Begin outermost mod
    match category {
        Category::Types => {
            write!(
                file,
                "\
                 /// This module contains all of the bare types, each\n\
                 /// represented by a `struct`. All of them implement\n\
                 /// [`Identifiable`], [`Serializable`] and [`Deserializable`].\n\
                 ///\n\
                 /// [`Identifiable`]: ../trait.Identifiable.html\n\
                 /// [`Serializable`]: ../trait.Serializable.html\n\
                 /// [`Deserializable`]: ../trait.Deserializable.html\n\
                 #[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]\n\
                 pub mod types {{\n\
                 "
            )?;
        }
        Category::Functions => {
            writeln!(
                file,
                "\
            /// This module contains all of the functions, each\n\
            /// represented by a `struct`. All of them implement\n\
            /// [`Identifiable`] and [`Serializable`].\n\
            ///\n\
            /// To find out the type that Telegram will return upon\n\
            /// invoking one of these requests, check out the associated\n\
            /// type in the corresponding [`RemoteCall`] trait impl.\n\
            ///\n\
            /// [`Identifiable`]: ../trait.Identifiable.html\n\
            /// [`Serializable`]: ../trait.Serializable.html\n\
            /// [`RemoteCall`]: trait.RemoteCall.html\n\
            #[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]\n\
            pub mod functions {{
            "
            )?;
        }
    }
    let grouped = grouper::group_by_ns(definitions, category);
    let mut sorted_keys: Vec<&String> = grouped.keys().collect();
    sorted_keys.sort();
    for key in sorted_keys.into_iter() {
        // Begin possibly inner mod
        let indent = if key.is_empty() {
            "    "
        } else {
            writeln!(file, "    #[allow(clippy::unreadable_literal)]")?;
            writeln!(file, "    pub mod {} {{", key)?;
            "        "
        };
        if category == Category::Types && config.impl_from_enum {
            // If all of the conversions are infallible this will be unused.
            // Don't bother checking this beforehand, just allow warnings.
            writeln!(file, "{}#[allow(unused_imports)]", indent)?;
            writeln!(file, "{}use std::convert::TryFrom;", indent)?;
        }
        for definition in grouped[key]
            .iter()
            .filter(|def| def.category == Category::Functions || !ignore_type(&def.ty))
        {
            write_definition(&mut file, indent, definition, metadata, config)?;
        }
        // End possibly inner mod
        if !key.is_empty() {
            writeln!(file, "    }}")?;
        }
    }
    // End outermost mod
    writeln!(file, "}}")
}
pub ( crate ) fn write_category_mod < W : Write > ( mut file : & mut W , category : Category , definitions : & [ Definition ] , metadata : & Metadata , config : & Config , ) -> io :: Result < ( ) > { // Begin outermost mod match category { Category :: Types => { write ! ( file " \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 " ) ? ; } Category :: Functions => { writeln ! ( file " \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 \n \
 " ) ? ; } } let grouped = grouper :: group_by_ns ( definitions , category ) ; let mut sorted_keys : Vec < & String > = grouped . keys ( ) . collect ( ) ; sorted_keys . sort ( ) ; for key in sorted_keys . into_iter ( ) { // Begin possibly inner mod let indent = if key . is_empty ( ) { " " } else { writeln ! ( file " " ) ? ; writeln ! ( file " " key ) ? ; " " } ; if category == Category :: Types && config . impl_from_enum { // If all of the conversions are infallible this will be unused. // Don't bother checking this beforehand, just allow warnings. writeln ! ( file " " indent ) ? ; writeln ! ( file " " indent ) ? ; } for definition in grouped [ key ] . iter ( ) . filter ( | def | def . category == Category :: Functions || ! ignore_type ( & def . ty ) ) { write_definition ( & mut file , indent , definition , metadata , config ) ? ; } // End possibly inner mod if ! key . is_empty ( ) { writeln ! ( file " " ) ? ; } } // End outermost mod writeln ! ( file " " ) }
Write an entire module for the desired category.
Write an entire module for the desired category .
file
&mut W
category
Category
definitions
&[Definition]
metadata
&Metadata
config
&Config
file
&mut W
category
Category
definitions
&[Definition]
metadata
&Metadata
config
&Config