A Sigmoid Dialogue [pdf]
aleph.se1 pointsby sciolizer0 comments
pub trait ToOwned {
type Owned: Borrow<Self>;
fn clone_into(&self, target: &mut Self::Owned) { ... }
}
Here the `Owned` is technically an input to `clone_into`, but of course semantically it's still an output. pub trait StreamExt: Stream {
type Item;
fn map<T, F>(self, f: F) -> Map<Self, F>
where F: FnMut(Self::Item) -> T,
Self: Sized { ... }
}
Here, the associated type `Item` is the input to the mapping function, and since the mapping function is an input to the map function, it is an input-to-an-input - which basically makes it an output. i.e. the stream "outputs" the items into the mapping function. (aka two contravariants make a covariant). pub trait Mul<Rhs> {
type Output;
fn mul(self, rhs: Rhs) -> Self::Output;
}
This begins the open declaration of the compile-time `Mul` function. It has two inputs: `Rhs` and `Self`. It has two outputs: `Output` and `mul` (the top-level runtime function). impl Mul<f32> for i32 {
type Output = f32;
fn mul(self, rhs: f32) -> Self::Output {
self as f32 * rhs
}
}
This adds a single cell to the `Mul` table. In psuedo-code, it's like we are saying: Mul[(i32,f32)] = (Output=f32, mul={self as f32 * rhs})
The cell is a pair of a type and a function. For traits with lots of functions, the cell is going to be mostly functions.