Repository: diesel-rs/diesel
File: diesel_cli/src/infer_schema_internals/data_structures.rs (Rust)

Code before:
        ))
    }

    fn for_type_path(t: &syn::TypePath, max_length: Option<u64>) -> Self {
        let last = t
            .path
            .segments
            .last()
            .expect("At least one segment in this type-path");

        let mut ret = Self {
            schema: None,
            rust_name: last.ident.to_string(),
            sql_name: String::new(),
            is_array: last.ident == "Array",
            is_nullable: last.ident == "Nullable",
            is_unsigned: last.ident == "Unsigned",
            max_length,
        };

        let sql_name = if !ret.is_nullable && !ret.is_array && !ret.is_unsigned {
            if last.ident == "PgLsn" {
                "pg_lsn".to_string()
            } else {
                last.ident
                    .to_string()
                    .split("_")
                    .collect::<Vec<_>>()
                    .join(" ")
            }
        } else if let syn::PathArguments::AngleBracketed(ref args) = last.arguments {
            let arg = args.args.first().expect("There is at least one argument");
            if let syn::GenericArgument::Type(syn::Type::Path(p)) = arg {
                let s = Self::for_type_path(p, max_length);
                ret.is_nullable |= s.is_nullable;
                ret.is_array |= s.is_array;
                ret.is_unsigned |= s.is_unsigned;
                s.sql_name
            } else {
                unreachable!("That shouldn't happen")
            }
        } else {
            unreachable!("That shouldn't happen")
        };
        ret.sql_name = sql_name;
        ret
    }
}

use std::fmt;


Review comment (suggestion):
It's unclear to me how this is consistent with what was previously written: previous writing seems to take something that's snake and turn it into separate words, while this seems to take something that's PascalCase, and turn it into snake, and I don't understand where these are mixed and this is a legitimate special case.
Could you please clarify this for me?
(Disclaimer: I have not investigated this in detail.)

Code after:
        ))
    }

    fn for_type_path(t: &syn::TypePath, max_length: Option<u64>) -> Self {
        let last = t
            .path
            .segments
            .last()
            .expect("At least one segment in this type-path");

        let mut ret = Self {
            schema: None,
            rust_name: last.ident.to_string(),
            sql_name: String::new(),
            is_array: last.ident == "Array",
            is_nullable: last.ident == "Nullable",
            is_unsigned: last.ident == "Unsigned",
            max_length,
        };

        let sql_name = if !ret.is_nullable && !ret.is_array && !ret.is_unsigned {
            if last.ident == "PgLsn" {
                "pg_lsn".to_string()
            } else {
                last.ident.to_string()
            }
        } else if let syn::PathArguments::AngleBracketed(ref args) = last.arguments {
            let arg = args.args.first().expect("There is at least one argument");
            if let syn::GenericArgument::Type(syn::Type::Path(p)) = arg {
                let s = Self::for_type_path(p, max_length);
                ret.is_nullable |= s.is_nullable;
                ret.is_array |= s.is_array;
                ret.is_unsigned |= s.is_unsigned;
                s.sql_name
            } else {
                unreachable!("That shouldn't happen")
            }
        } else {
            unreachable!("That shouldn't happen")
        };
        ret.sql_name = sql_name;
        ret
    }
}

use std::fmt;

impl fmt::Display for ColumnType {
    fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        if self.is_nullable {
            write!(out, "Nullable<")?;