# 1.21.0[−][src]Function core::mem::discriminant

    pub fn discriminant<T>(v: &T) -> Discriminant<T>

Returns a value uniquely identifying the enum variant in `v`.

If `T` is not an enum, calling this function will not result in undefined behavior, but the return value is unspecified.

# Stability

The discriminant of an enum variant may change if the enum definition changes. A discriminant of some variant will not change between compilations with the same compiler.

# Examples

This can be used to compare enums that carry data, while disregarding the actual data:

    use std::mem;

    enum Foo { A(&'static str), B(i32), C(i32) }

    assert!(mem::discriminant(&Foo::A("bar")) == mem::discriminant(&Foo::A("baz")));
    assert!(mem::discriminant(&Foo::B(1))     == mem::discriminant(&Foo::B(2)));
    assert!(mem::discriminant(&Foo::B(3))     != mem::discriminant(&Foo::C(3)));Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)