forked from M-Labs/artiq
firmware: impl std_artiq::io::{Read,Write} for io::{Read,Write}.
This commit is contained in:
parent
bfc8fd0807
commit
2999756493
|
@ -130,6 +130,7 @@ name = "io"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"std_artiq 0.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -208,6 +209,7 @@ dependencies = [
|
||||||
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"dyld 0.0.0",
|
"dyld 0.0.0",
|
||||||
|
"io 0.0.0",
|
||||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"std_artiq 0.0.0",
|
"std_artiq 0.0.0",
|
||||||
]
|
]
|
||||||
|
@ -226,6 +228,7 @@ dependencies = [
|
||||||
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"drtioaux 0.0.0",
|
"drtioaux 0.0.0",
|
||||||
"fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)",
|
"fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)",
|
||||||
|
"io 0.0.0",
|
||||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"logger_artiq 0.0.0",
|
"logger_artiq 0.0.0",
|
||||||
"managed 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"managed 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -9,6 +9,7 @@ path = "lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = { version = "1.0", default-features = false, optional = true }
|
byteorder = { version = "1.0", default-features = false, optional = true }
|
||||||
|
std_artiq = { path = "../libstd_artiq", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
alloc = []
|
alloc = []
|
||||||
|
|
|
@ -8,6 +8,9 @@ extern crate alloc;
|
||||||
#[cfg(feature = "byteorder")]
|
#[cfg(feature = "byteorder")]
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
|
|
||||||
|
#[cfg(feature = "std_artiq")]
|
||||||
|
extern crate std_artiq;
|
||||||
|
|
||||||
use core::result;
|
use core::result;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
|
@ -185,3 +188,44 @@ impl<T: ::alloc::Vec<[u8]>> Write for Cursor<T> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std_artiq")]
|
||||||
|
impl<T> Read for T where T: std_artiq::io::Read {
|
||||||
|
type ReadError = std_artiq::io::Error;
|
||||||
|
|
||||||
|
fn read(&mut self, buf: &mut [u8]) -> result::Result<usize, Self::ReadError> {
|
||||||
|
std_artiq::io::Read::read(self, buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std_artiq")]
|
||||||
|
impl<T> Write for T where T: std_artiq::io::Write {
|
||||||
|
type WriteError = std_artiq::io::Error;
|
||||||
|
type FlushError = std_artiq::io::Error;
|
||||||
|
|
||||||
|
fn write(&mut self, buf: &[u8]) -> result::Result<usize, Self::WriteError> {
|
||||||
|
std_artiq::io::Write::write(self, buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> result::Result<(), Self::WriteError> {
|
||||||
|
std_artiq::io::Write::flush(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std_artiq")]
|
||||||
|
impl<T> From<Error<T>> for std_artiq::io::Error
|
||||||
|
where T: Into<std_artiq::io::Error>
|
||||||
|
{
|
||||||
|
fn from(value: Error<T>) -> std_artiq::io::Error {
|
||||||
|
match value {
|
||||||
|
Error::UnexpectedEof =>
|
||||||
|
std_artiq::io::Error::new(std_artiq::io::ErrorKind::UnexpectedEof,
|
||||||
|
"unexpected end of stream"),
|
||||||
|
Error::Unrecognized =>
|
||||||
|
std_artiq::io::Error::new(std_artiq::io::ErrorKind::InvalidData,
|
||||||
|
"unrecognized data"),
|
||||||
|
Error::Other(err) =>
|
||||||
|
err.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue