New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in smallint to enum macro #1892

Closed
sackery opened this Issue Oct 21, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@sackery

sackery commented Oct 21, 2018

pub macro enum_number {
    ($name:ident { $first:ident = $first_value:expr, $($variant:ident = $value:expr, )* }) => {
        #[derive(Debug, PartialEq, FromSqlRow, AsExpression)]
        #[sql_type = "SmallInt"]
        pub enum $name {
            $first = $first_value,
            $($variant = $value,)*
        }

        impl ::std::default::Default for $name {
            fn default() -> $name {
                $name::$first
            }
        }

        impl ::diesel::serialize::ToSql<::diesel::sql_types::SmallInt, ::diesel::pg::Pg> for $name {
            fn to_sql<W: std::io::Write>(&self, out: &mut ::diesel::serialize::Output<W, ::diesel::pg::Pg>) -> ::diesel::serialize::Result {
                ::diesel::serialize::ToSql::<::diesel::sql_types::SmallInt, ::diesel::pg::Pg>::to_sql(&(*self as i16), out)
            }
        }

        impl ::diesel::deserialize::FromSql<::diesel::sql_types::SmallInt, ::diesel::pg::Pg> for $name {
            fn from_sql(bytes: Option<&[u8]>) -> ::diesel::deserialize::Result<Self> {
                let value: i16 = ::diesel::deserialize::FromSql::<::diesel::sql_types::SmallInt, ::diesel::pg::Pg>::from_sql(bytes)?;

                match value {
                    $first_value => Ok($name::$first),
                    $( $value => Ok($name::$variant), )*
                    _ => Err("Unrecognized enum variant".into()),
                }
            }
        }
}
error[E0412]: cannot find type `SmallInt` in this scope
 --> santry/src/handlers/api/search.rs:5:1
  |
5 | / enum_number! {SearchType {
6 | |     Node = 0,
7 | |     User = 1,
8 | | }}
  | |__^ not found in this scope
@sgrif

This comment has been minimized.

Member

sgrif commented Oct 21, 2018

You need to use the type, or fully qualify it as you have everywhere else. Please do not use the issue tracker to ask for help in the future. It should only be used for reporting bugs. Our gitter channel or discourse are the correct places to ask for help.

@sgrif sgrif closed this Oct 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment