Related to #15 Sodium enforces that every value must be passed by reference to the closures doing the work the user actually wants the system to do.
In the case of very small values this is a completely unnecessary performance hit, and results in very unidiomatic Rust code where there are shared references everywhere and they all need to be dereferenced.
It would be ideal if the Sodium combinators allowed the user to have control over the standard Rust affordances regarding ownership and borrowing (excluding mutable borrowing).
This would require changing or removing the current IsLambda* traits because those are part of what enforces that every argument is a reference.
I think my idea of making it an explicit operation to make a Stream shareable would provide the seam needed to introduce this concept.
In particular, Streams should default to retaining full ownership over their values, letting combinators that don't consume the value borrow it instead.
Then there should be three ways to explicitly share a value, by Copy, by Clone and by a shared reference &T.
This last possibility actually presents a significant design challenge and might not be possible. The other alternative would be to use a reference-counted share, i.e. Arc or Rc.
The point here is that in order to make this abstraction as low cost as possible, we shouldn't have to pay for copying or cloning when we don't need it.
Related to #15 Sodium enforces that every value must be passed by reference to the closures doing the work the user actually wants the system to do.
In the case of very small values this is a completely unnecessary performance hit, and results in very unidiomatic Rust code where there are shared references everywhere and they all need to be dereferenced.
It would be ideal if the Sodium combinators allowed the user to have control over the standard Rust affordances regarding ownership and borrowing (excluding mutable borrowing).
This would require changing or removing the current
IsLambda*
traits because those are part of what enforces that every argument is a reference.I think my idea of making it an explicit operation to make a
Stream
shareable would provide the seam needed to introduce this concept.In particular,
Stream
s should default to retaining full ownership over their values, letting combinators that don't consume the value borrow it instead.Then there should be three ways to explicitly share a value, by
Copy
, byClone
and by a shared reference&T
.This last possibility actually presents a significant design challenge and might not be possible. The other alternative would be to use a reference-counted share, i.e.
Arc
orRc
.The point here is that in order to make this abstraction as low cost as possible, we shouldn't have to pay for copying or cloning when we don't need it.