-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
algebra_core::io module inconsistent with std::io #5
Comments
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 |
|
I'm now using 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. |
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. ",
))
}
} |
But also, what is the |
(Eventually, I plan on getting rid of |
Make sense. There may be some other crates that need |
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 I've no idea if functionality like canonical serialization should work like |
This is fixed now in |
When the
std
feature is on,algebra_core
chooses to reexport thestd::io
library instead of using its ownio
package. However, some of the implementation in theio
package is inconsistent with thestd::io
library. It might cause some confusion and user has to handle both cases when inconsistency happens.For example, when user tries to use the Error struct in the
io
package, when inno_std
mode, it is fine to returnErr(algebra_core::io::Error)
, while when thestd
feature is on it won't compile.It is because the IO Error implemented by algebra_core is
while Error in std::io is
It might be better to make
algebra_core::io
more consistent to the standard library, or just use theio
package instead of reexportingstd::io
package regardless of whetherstd
feature is on or off to avoid confusion.The text was updated successfully, but these errors were encountered: