Place

Struct Place 

Source
pub struct Place(/* private fields */);
Expand description

A Place is a structured way to represent a postal address.

Note: it is internally represented as an EnumMap to easily loop over all the fields

Methods from Deref<Target = EnumMap<Component, Option<String>>>§

Source

pub fn values(&self) -> Values<'_, V>

An iterator visiting all values. The iterator type is &V.

§Examples
use enum_map::enum_map;

let map = enum_map! { false => 3, true => 4 };
let mut values = map.values();
assert_eq!(values.next(), Some(&3));
assert_eq!(values.next(), Some(&4));
assert_eq!(values.next(), None);
Source

pub fn values_mut(&mut self) -> ValuesMut<'_, V>

An iterator visiting all values mutably. The iterator type is &mut V.

§Examples
use enum_map::enum_map;

let mut map = enum_map! { _ => 2 };
for value in map.values_mut() {
    *value += 2;
}
assert_eq!(map[false], 4);
assert_eq!(map[true], 4);
Source

pub fn clear(&mut self)

Clear enum map with default values.

§Examples
use enum_map::{Enum, EnumMap};

#[derive(Enum)]
enum Example {
    A,
    B,
}

let mut enum_map = EnumMap::<_, String>::default();
enum_map[Example::B] = "foo".into();
enum_map.clear();
assert_eq!(enum_map[Example::A], "");
assert_eq!(enum_map[Example::B], "");
Source

pub fn iter(&self) -> Iter<'_, K, V>

Returns an iterator over enum map.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Returns a mutable iterator over enum map.

Source

pub fn len(&self) -> usize

Returns number of elements in enum map.

Source

pub fn swap(&mut self, a: K, b: K)

Swaps two indexes.

§Examples
use enum_map::enum_map;

let mut map = enum_map! { false => 0, true => 1 };
map.swap(false, true);
assert_eq!(map[false], 1);
assert_eq!(map[true], 0);
Source

pub fn as_slice(&self) -> &[V]

Converts an enum map to a slice representing values.

Source

pub fn as_mut_slice(&mut self) -> &mut [V]

Converts a mutable enum map to a mutable slice representing values.

Trait Implementations§

Source§

impl Debug for Place

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Place

Source§

fn default() -> Place

Returns the “default value” for a type. Read more
Source§

impl DerefMut for Place

Source§

fn deref_mut(&mut self) -> &mut EnumMap<Component, Option<String>>

Mutably dereferences the value.
Source§

impl<'a, T> From<T> for Place
where T: IntoIterator<Item = (Component, &'a str)>,

Source§

fn from(data: T) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Place

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Deref for Place

Source§

type Target = EnumMap<Component, Option<String>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Place

§

impl RefUnwindSafe for Place

§

impl Send for Place

§

impl Sync for Place

§

impl Unpin for Place

§

impl UnwindSafe for Place

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.