# Trait core::marker::Reflect [−] [src]

    pub trait Reflect { }

Deprecated since 1.14.0

: Specialization makes parametricity impossible

Unstable (`reflect_marker` #27749)

: Specialization makes parametricity impossible

Types that can be reflected over.

By "reflection" we mean use of the `Any` trait, or related machinery such as `TypeId`.

`Reflect` is implemented for all types. Its purpose is to ensure that when you write a generic function that will employ reflection, that must be reflected (no pun intended) in the generic bounds of that function.

    #![feature(reflect_marker)]
    use std::marker::Reflect;
    use std::any::Any;

    fn foo<T: Reflect + 'static>(x: &T) {
        let any: &Any = x;
        if any.is::<u32>() { println!("u32"); }
    }Run

Without the bound `T: Reflect`, `foo` would not typecheck. (As a matter of style, it would be preferable to write `T: Any`, because `T: Any` implies `T: Reflect` and `T: 'static`, but we use `Reflect` here for illustrative purposes.)

The `Reflect` bound serves to alert `foo`'s caller to the fact that `foo` may behave differently depending on whether `T` is `u32` or not. The ability for a caller to reason about what a function may do based solely on what generic bounds are declared is often called the "parametricity property". Despite the use of `Reflect`, Rust lacks true parametricity because a generic function can, at the very least, call `mem::size_of` without employing any trait bounds whatsoever.

## Implementors

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand 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`)