Comments (9)
I agree that it is unnatural (I need to handle this specifically when writing my code).
Some thinking:
There is a downside for "use the io
package instead of reexporting std::io
package regardless of whether std
feature is on or off". In this case, our Read
or Write
would not naturally compose with other packets using std::io
.
from std.
std::io
is not available in no_std
(there is no equivalent in core
or alloc
, so we can't just re-export it. If you could post your code snippet here that would be great.
from std.
I'm now using cfg
switch in my code like this:
impl<F: Field> ToBytes for XZZPS19PMsg<F> {
#[cfg(not(feature = "std"))]
fn write<W: Write>(&self, writer: W) -> IOResult<()> {
match self.serialize(writer) {
Ok(()) => Ok(()),
Err(_e) => Err(IOError),
}
}
#[cfg(feature = "std")]
fn write<W: Write>(&self, writer: W) -> IOResult<()> {
match self.serialize(writer) {
Ok(()) => Ok(()),
Err(_e) => Err(IOError::new(
ErrorKind::InvalidData,
"Cannot serialize message. ",
)),
}
}
}
It might be better if there's no need to handle both cases manually.
from std.
For the time being, to make the code shorter, you could change it to something like
impl<F: Field> ToBytes for XZZPS19PMsg<F> {
fn write<W: Write>(&self, writer: W) -> IOResult<()> {
#[cfg(not(feature = "std"))]
self.serialize(writer).map_err(|_| IOError)
#[cfg(feature = "std")]
self.serialize(writer).map_err(|_| IOError::new(
ErrorKind::InvalidData,
"Cannot serialize message. ",
))
}
}
from std.
But also, what is the serialize
method from? Is it from CanonicalSerialize
? If so, I can try to add a Into<io::Error>
impl on serialize::Error
.
from std.
(Eventually, I plan on getting rid of to_bytes!
and ToBytes
and FromBytes
; these conversions are currently unprincipled and should be replaced by CanonicalSerialize
/CanonicalDeserialize
)
from std.
Make sense. There may be some other crates that need ToBytes
and FromBytes
trait, so I believe it's good to impl Into<io::Error>
on serialize::Error
.
from std.
At present, there is little option besides using some "serialization framework" for no_std, so CanonicalSerialize/CanonicalDeserialize here.
It's plausible the new error handling project group rust-lang/rfcs#2965 selects some error type and trait that work without std, like https://github.com/yaahc/nostd-error-poc or maybe rust-lang/rust#48331 An obvious approach is some SmallBox<dyn Error>
type ala https://internals.rust-lang.org/t/idea-fixed-sized-traits/12179/8?u=jeffburdges so any T: Error
always works, even without alloc, provide T
is smaller than 8 bytes, and larger T
panics without alloc. After an error type exists that works with OS errors, native crate errors, and does not strictly require alloc, then either the traits in std::io
become core::io
or some similar fork appears.
I've no idea if functionality like canonical serialization should work like std::io
but it might become possible down the road.
from std.
This is fixed now in ark-std
. (For common APIs)
from std.
Related Issues (13)
- ark-std does not compile in `no_std` HOT 4
- What became of bench utils? HOT 1
- Add method for randomly sampling non-zero elements HOT 1
- Export `rand::Rng` from `ark_std::rand`
- A new README for utils HOT 1
- Rename `log2` to `log2_of_next_power_of_two`
- Replace `UniformRand` by `CryptoRng + R` HOT 1
- `ark_std::error` vs `core::error` HOT 3
- Infinite dot when some spawned thread crash which make indent more than 75 HOT 1
- Code timing instrumentation HOT 7
- Investigate parallelization for wasm with `web_worker` HOT 1
- WASM compilation/Webapp proof of concept HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from std.