> ## Documentation Index
> Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
> Use this file to discover all available pages before exploring further.

# core::traits::Default

A trait for giving a type a useful default value.
Cairo implements `Default` for various primitives types.

This trait can be used with `#[derive]` if all of the type's fields implement
`Default`. When `derive`d, it will use the default value for each field's type.

<Info>
  When using `#[derive(Default)]` on an `enum`, you need to choose which unit variant will be
  default. You do this by placing the `#[default]` attribute on the variant.

  ```rust theme={null}
  #[derive(Default)]
  enum Kind {
      #[default]
      A,
      B,
      C,
  }
  ```

  You can even use the `#[default]` attribute even on non-unit variants, provided that the
  associated type implements `Default`.
</Info>

## Signature

```rust theme={null}
pub trait Default
```

## Examples

```rust theme={null}
#[derive(Drop, Default, PartialEq)]
struct SomeOptions {
    foo: i32,
    bar: u32,
}

assert!(Default::default() == SomeOptions { foo: 0, bar: 0 });
```

To implement `Default`, provide an implementation for the `default()` method that returns the value of your type that should be the default:

```rust theme={null}
#[derive(Copy, Drop)]
enum Kind {
    A,
    B,
    C,
}

impl DefaultKind of Default {
    fn default() -> Kind { Kind::A }
}
```

## Trait functions

### default

Returns the "default value" for a type.
Default values are often some kind of initial value, identity value, or anything else that
may make sense as a default.

#### Signature

```rust theme={null}
fn default() -> T
```

#### Examples

```rust theme={null}
let i: i8 = Default::default();
let (x, y): (Option, u64) = Default::default();
let (a, b, (c, d)): (i32, u32, (bool, bool)) = Default::default();
```
