# 1.0.0[−]Primitive Type unit

The `()` type, sometimes called "unit" or "nil".

The `()` type has exactly one value `()`, and is used when there is no other meaningful value that could be returned. `()` is most commonly seen implicitly: functions without a `-> ...` implicitly have return type `()`, that is, these are equivalent:

    fn long() -> () {}

    fn short() {}Run

The semicolon `;` can be used to discard the result of an expression at the end of a block, making the expression (and thus the block) evaluate to `()`. For example,

    fn returns_i64() -> i64 {
        1i64
    }
    fn returns_unit() {
        1i64;
    }

    let is_i64 = {
        returns_i64()
    };
    let is_unit = {
        returns_i64();
    };Run

## Trait Implementations

###

`impl FromIterator<()> for ()`

1.23.0
[src]

Collapses all unit items from an iterator into one.

This is more useful when combined with higher-level abstractions, like collecting to a `Result<(), E>` where you only care about errors:

    use std::io::*;
    let data = vec![1, 2, 3, 4, 5];
    let res: Result<()> = data.iter()
        .map(|x| writeln!(stdout(), "{}", x))
        .collect();
    assert!(res.is_ok());Run

####

`fn from_iter<I>(iter: I) where I: IntoIterator<Item = ()>,`

[src]

Creates a value from an iterator. Read more

###

`impl Extend<()> for ()`

1.28.0
[src]

####

`fn extend<T>(&mut self, iter: T) where T: IntoIterator<Item = ()>,`

[src]

Extends a collection with the contents of an iterator. Read more

###

`impl Default for ()`

[src]

####

`fn default()`

[src]

Returns the default value of `()`

###

`impl Hash for ()`

[src]

####

`fn hash<H>(&self, _state: &mut H) where H: Hasher,`

[src]

Feeds this value into the given [`Hasher`]. Read more

####

`fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher,`

1.3.0
[src]

Feeds a slice of this type into the given [`Hasher`]. Read more

###

`impl PartialOrd<()> for ()`

[src]

####

`fn partial_cmp(&self, &()) -> Option<Ordering>`

[src]

This method returns an ordering between `self` and `other` values if one exists. Read more

####

`#[must_use] fn lt(&self, other: &Rhs) -> bool`

[src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

####

`#[must_use] fn le(&self, other: &Rhs) -> bool`

[src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

####

`#[must_use] fn gt(&self, other: &Rhs) -> bool`

[src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

####

`#[must_use] fn ge(&self, other: &Rhs) -> bool`

[src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

###

`impl Ord for ()`

[src]

####

`fn cmp(&self, _other: &()) -> Ordering`

[src]

This method returns an `Ordering` between `self` and `other`. Read more

####

`fn max(self, other: Self) -> Self`

1.21.0
[src]

Compares and returns the maximum of two values. Read more

####

`fn min(self, other: Self) -> Self`

1.21.0
[src]

Compares and returns the minimum of two values. Read more

###

`impl Debug for ()`

[src]

####

`fn fmt(&self, f: &mut Formatter) -> Result<(), Error>`

[src]

Formats the value using the given formatter. Read more

###

`impl Eq for ()`

[src]

###

`impl PartialEq<()> for ()`

[src]

####

`fn eq(&self, _other: &()) -> bool`

[src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

####

`fn ne(&self, _other: &()) -> bool`

[src]

This method tests for `!=`.

###

`impl Termination for ()`

[src]

####

`fn report(self) -> i32`

[src]

🔬 This is a nightly-only experimental API. (`termination_trait_lib` #43301)

Is called to get the representation of the value as status code. This status code is returned to the operating system. Read more

# 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`)