> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/v6.0.0/llms.txt

# Trait StateVariable

Module: `noir_aztec::state_vars`

```rust
pub trait StateVariable<let N: u32, Context> {
    // Required methods
    pub fn new(context: Context, storage_slot: Field) -> Self;
    pub fn get_storage_slot(self) -> Field;
}
```

A container for contract state.

All contract state is stored in state variables, and all state variables implement the `StateVariable` trait. For more information on the different types of state variables see the [`state_vars`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/index.md) module.

## Required methods

```rust
pub fn new(context: Context, storage_slot: Field) -> Self
```

Creates a state variable.

This function is automatically called by aztec-nr as the [`self`](/aztec-nr-api/v6.0.0/noir_aztec/contract_self/index.md) object is created. Users are expected to only ever need to invoke it when using the [`#[storage_no_init]`](/aztec-nr-api/v6.0.0/noir_aztec/macros/storage/fn.storage_no_init.md) macro.

```rust
pub fn get_storage_slot(self) -> Field
```

Returns the state variable's storage slot.

## Implementors

```rust
impl<Context, let InitialDelay: u64, let M: u32, T> StateVariable<M + 1, Context> for DelayedPublicMutable<T, InitialDelay, Context>
where
    DelayedPublicMutableValues<T, InitialDelay>: Packable<N = M>
```

```rust
impl<Context, K, V> StateVariable<1, Context> for Map<K, V, Context>
```

```rust
impl<Context, V> StateVariable<1, Context> for Owned<V, Context>
```

```rust
impl<Context, let M: u32, T> StateVariable<M + 1, Context> for PublicImmutable<T, Context>
where
    T: Packable<N = M>
```

```rust
impl<Context, let M: u32, T> StateVariable<M, Context> for PublicMutable<T, Context>
where
    T: Packable<N = M>
```

```rust
impl<Context, Note> StateVariable<1, Context> for SinglePrivateImmutable<Note, Context>
```

```rust
impl<Context, Note> StateVariable<1, Context> for SinglePrivateMutable<Note, Context>
```
