Struct mononym::Seed[][src]

pub struct Seed<N>(_);
Expand description

A unique seed type for generating new unique names. mononym guarantees that there can never be two seed value of the same type Seed<N> with the same name type N.

A Seed value is required to generate new names for values to be used in types such as Named. A seed value can be obtained by either making functions accept a Seed<impl Name> as its argument, or creating fresh Seed value using with_seed.

Implementations

Consumes the seed and returns a value with a unique type impl Name. The value on its own do not have much use, however it can be used as a proxy type for users to define their own name-based abstractions.

Consumes the seed and a value of type T and turn it into a named value Named<impl HasType<T>, T>. The returned named value have a unique type-level name that implements both Name and HasType<T>.

Consumes the seed and returns two new seeds Seed<impl Name> with unique names and thus of different types.

mononym guarantees that each replicated seed will generate different names, thereby guarantee that the names are always unique.

For example, the following code should fail with compile error:

fn same<T>(_: T, _: T) {}
fn test(seed: Seed<impl Name>) {
  let (seed1, seed2) = seed.replicate();
  same(seed1, seed2); // error
  same(seed1.new_named(()), seed2.new_named(())); // error
}

For convenience, mononym also provides the replicate functions from Seed::replicate_3 up to Seed::replicate_8 to allow easy replication of the seed for 2-8 times. User can call the replicate functions multiple times if they need more than 8 seed replications, which should be rarely happen.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.