pub trait ObjectArgument<T>: IntoIterator<Item = T> {
    type SameSize<R>;
    type SizePlusOne<R>;

    // Required methods
    fn num_objects(&self) -> usize;
    fn map<F, R>(self, f: F) -> Self::SameSize<R>
       where F: FnMut(T) -> R;
    fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>
       where F: FnMut(T) -> R;
}
Expand description

Pass objects to a builder method

Many builder methods receive objects as arguments, and many builder arguments return objects back, based on their input. In the general case, the number of objects passed and returned is usually arbitrary, but many callers pass a specific number of objects, and expect the same number of objects back.

This trait can be used to do exactly that. It is implemented for Vec and arrays. When passing a Vec, a Vec is returned. When passing an array, an array of the same size is returned.

Required Associated Types§

source

type SameSize<R>

The value returned, if the implementing type is passed on an argument

The return value has the same length as the implementing type, but it is not necessarily of the same type. For this reason, this associated type is generic.

source

type SizePlusOne<R>

A return value that has one more element than the argument

Required Methods§

source

fn num_objects(&self) -> usize

Return the number of objects

source

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

Create a return value by mapping the implementing type

source

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

Create a return value with one more element

Implementations on Foreign Types§

source§

impl<T> ObjectArgument<T> for Vec<T>

§

type SameSize<R> = Vec<R, Global>

§

type SizePlusOne<R> = Vec<R, Global>

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 0]

§

type SameSize<R> = [R; 0]

§

type SizePlusOne<R> = [R; 1]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 1]

§

type SameSize<R> = [R; 1]

§

type SizePlusOne<R> = [R; 2]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 2]

§

type SameSize<R> = [R; 2]

§

type SizePlusOne<R> = [R; 3]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 3]

§

type SameSize<R> = [R; 3]

§

type SizePlusOne<R> = [R; 4]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 4]

§

type SameSize<R> = [R; 4]

§

type SizePlusOne<R> = [R; 5]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 5]

§

type SameSize<R> = [R; 5]

§

type SizePlusOne<R> = [R; 6]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 6]

§

type SameSize<R> = [R; 6]

§

type SizePlusOne<R> = [R; 7]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

source§

impl<T> ObjectArgument<T> for [T; 7]

§

type SameSize<R> = [R; 7]

§

type SizePlusOne<R> = [R; 8]

source§

fn num_objects(&self) -> usize

source§

fn map<F, R>(self, f: F) -> Self::SameSize<R>where F: FnMut(T) -> R,

source§

fn map_plus_one<F, R>(self, item: R, f: F) -> Self::SizePlusOne<R>where F: FnMut(T) -> R,

Implementors§