Remove core_io when no_std.
Ref: https://github.com/fluffysquirrels/framed-rs/issues/3
This commit is contained in:
parent
15456af48a
commit
872e6e3ceb
3 changed files with 6 additions and 23 deletions
|
@ -13,10 +13,6 @@ repository = "https://github.com/fluffysquirrels/framed"
|
||||||
cobs = "^0.1.3"
|
cobs = "^0.1.3"
|
||||||
ref_slice = "^1.1.1"
|
ref_slice = "^1.1.1"
|
||||||
|
|
||||||
[dependencies.core-io]
|
|
||||||
git = "https://github.com/QuiltOS/core-io"
|
|
||||||
rev = "f084f913011c9916d420b520ead3953a2ccb950e"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["use_std"]
|
default = ["use_std"]
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use core::result;
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
#[cfg_attr(feature = "use_std", derive(Debug))]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// COBS decode failed
|
/// COBS decode failed
|
||||||
CobsDecodeFailed,
|
CobsDecodeFailed,
|
||||||
|
@ -21,12 +21,6 @@ pub enum Error {
|
||||||
/// Forwarded io::Error.
|
/// Forwarded io::Error.
|
||||||
#[cfg(feature = "use_std")]
|
#[cfg(feature = "use_std")]
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
|
|
||||||
/// Forwarded Io error.
|
|
||||||
///
|
|
||||||
/// TODO: Store some extra value here.
|
|
||||||
#[cfg(not(feature = "use_std"))]
|
|
||||||
Io,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "use_std")]
|
#[cfg(feature = "use_std")]
|
||||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -24,8 +24,6 @@
|
||||||
#![cfg_attr(not(feature = "use_std"), no_std)]
|
#![cfg_attr(not(feature = "use_std"), no_std)]
|
||||||
|
|
||||||
extern crate cobs;
|
extern crate cobs;
|
||||||
#[cfg(not(feature = "use_std"))]
|
|
||||||
extern crate core_io;
|
|
||||||
|
|
||||||
extern crate ref_slice;
|
extern crate ref_slice;
|
||||||
|
|
||||||
|
@ -42,16 +40,15 @@ use ref_slice::ref_slice_mut;
|
||||||
#[cfg(feature = "use_std")]
|
#[cfg(feature = "use_std")]
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
|
|
||||||
#[cfg(not(feature = "use_std"))]
|
|
||||||
use core_io::{Read, Write};
|
|
||||||
|
|
||||||
const FRAME_END: u8 = 0;
|
const FRAME_END: u8 = 0;
|
||||||
|
|
||||||
/// Sends frames over an underlying `io::Write` instance.
|
/// Sends frames over an underlying `io::Write` instance.
|
||||||
|
#[cfg(feature = "use_std")]
|
||||||
pub struct Sender<W: Write> {
|
pub struct Sender<W: Write> {
|
||||||
w: W,
|
w: W,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "use_std")]
|
||||||
impl<W: Write> Sender<W> {
|
impl<W: Write> Sender<W> {
|
||||||
pub fn new(w: W) -> Sender<W> {
|
pub fn new(w: W) -> Sender<W> {
|
||||||
Sender::<W> {
|
Sender::<W> {
|
||||||
|
@ -70,11 +67,6 @@ impl<W: Write> Sender<W> {
|
||||||
self.w.write(&code)?;
|
self.w.write(&code)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "use_std"))] {
|
|
||||||
self.w.write(&code)
|
|
||||||
.map_err(|_| Error::Io)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +75,7 @@ impl<W: Write> Sender<W> {
|
||||||
///
|
///
|
||||||
/// TODO: Add a recv() variant suitable for no_std use, e.g. one that
|
/// TODO: Add a recv() variant suitable for no_std use, e.g. one that
|
||||||
/// takes a `&mut [u8]`.
|
/// takes a `&mut [u8]`.
|
||||||
|
#[cfg(feature = "use_std")]
|
||||||
pub struct Receiver<R: Read> {
|
pub struct Receiver<R: Read> {
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "use_std"), allow(dead_code))]
|
#[cfg_attr(not(feature = "use_std"), allow(dead_code))]
|
||||||
|
@ -90,6 +83,7 @@ pub struct Receiver<R: Read> {
|
||||||
r: R,
|
r: R,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "use_std")]
|
||||||
impl<R: Read> Receiver<R> {
|
impl<R: Read> Receiver<R> {
|
||||||
pub fn new(r: R) -> Receiver<R> {
|
pub fn new(r: R) -> Receiver<R> {
|
||||||
Receiver::<R> {
|
Receiver::<R> {
|
||||||
|
@ -97,7 +91,6 @@ impl<R: Read> Receiver<R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "use_std")]
|
|
||||||
pub fn recv(&mut self) -> Result<Vec<u8>> {
|
pub fn recv(&mut self) -> Result<Vec<u8>> {
|
||||||
let mut next_frame = Vec::new();
|
let mut next_frame = Vec::new();
|
||||||
|
|
||||||
|
@ -132,7 +125,7 @@ impl<R: Read> Receiver<R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, not(feature = "use_std")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use channel::Channel;
|
use channel::Channel;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
|
Loading…
Reference in a new issue