Skip to main content

TupleReplicate

Trait TupleReplicate 

Source
pub trait TupleReplicate<T> {
    // Required method
    fn tuple_replicate(value: T) -> Self;
}
Expand description

A trait for replicating a value into a tuple.

This trait allows creating a tuple where all elements are the same value. The implementation is optimized to avoid unnecessary cloning: for empty tuples and single-element tuples, no Clone bound is required. For tuples with 2+ elements, Clone is required but the original value is moved to the last position to minimize clones.

Part of the tuplities crate.

Required Methods§

Source

fn tuple_replicate(value: T) -> Self

Creates a tuple where all elements are the provided value.

§Examples
use tuplities_replicate::TupleReplicate;

let tuple: (i32, i32, i32) = TupleReplicate::tuple_replicate(42);
assert_eq!(tuple, (42, 42, 42));
let _tuple_empty: () = TupleReplicate::tuple_replicate(42);
let tuple_single: (i32,) = TupleReplicate::tuple_replicate(42);
assert_eq!(tuple_single, (42,));
let tuple_two: (i32, i32) = TupleReplicate::tuple_replicate(42);
assert_eq!(tuple_two, (42, 42));

let tuple_refs: (&str, &str, &str) = TupleReplicate::tuple_replicate("hello");
assert_eq!(tuple_refs, ("hello", "hello", "hello"));

let tuple_strings: (String, String) = TupleReplicate::tuple_replicate(String::from("world"));
assert_eq!(tuple_strings, (String::from("world"), String::from("world")));

let tuple_refs2: (&i32, &i32) = TupleReplicate::tuple_replicate(&100);
assert_eq!(tuple_refs2, (&100, &100));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T, T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T, T, T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<'a, 'b, T> TupleReplicate<T> for (T, T, T, T, T, T, T, T)
where T: 'a + Clone, Self: 'b, 'a: 'b,

Source§

fn tuple_replicate(value: T) -> Self

Source§

impl<T> TupleReplicate<T> for ()

Source§

fn tuple_replicate(_value: T) -> Self

Source§

impl<T> TupleReplicate<T> for (T,)

Source§

fn tuple_replicate(value: T) -> Self

Implementors§