concision_traits/
init.rs

1/*
2    Appellation: init <module>
3    Created At: 2026.01.13:18:38:50
4    Contrib: @FL03
5*/
6
7/// [`InitWith`] enables a container to
8pub trait InitWith<F, U> {
9    type Cont<T>;
10    /// consumes the current instance to initialize a new one
11    fn init_with(f: F) -> Self::Cont<U>
12    where
13        F: FnOnce() -> U,
14        Self: Sized;
15}
16
17#[cfg(feature = "rand")]
18/// The [`InitRand`] trait provides a generic interface for initializing objects using
19/// random number generators. This trait is particularly useful for types that require
20/// random initialization, such as neural network weights, biases, or other parameters.
21pub trait InitRand<R: rand_core::RngCore> {
22    type Output;
23    /// use the provided random number generator `rng` to initialize the object
24    fn init_random(rng: &mut R) -> Self::Output;
25}
26
27/// [`Initialize`] provides a mechanism for _initializing_ some object using a value of type
28/// `T` to produce another object.
29pub trait Initialize<T> {
30    type Output;
31    /// initializes the object using the given value, consuming the caller to produce another
32    /// object
33    fn init(self, with: T) -> Self::Output;
34}