Made some progress towards effectful programs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::io;
|
||||
use std::num::NonZero;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -58,6 +59,20 @@ pub struct IoError {
|
||||
pub message: String,
|
||||
pub kind: IoErrorKind,
|
||||
}
|
||||
impl From<io::Error> for IoError {
|
||||
fn from(value: io::Error) -> Self {
|
||||
Self {
|
||||
message: value.to_string(),
|
||||
kind: match value.kind() {
|
||||
io::ErrorKind::Interrupted
|
||||
| io::ErrorKind::BrokenPipe
|
||||
| io::ErrorKind::NetworkDown
|
||||
| io::ErrorKind::ConnectionReset => IoErrorKind::Interrupted,
|
||||
_ => IoErrorKind::Other,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub enum ReadLimit {
|
||||
@@ -69,7 +84,9 @@ pub enum ReadLimit {
|
||||
/// Read all available data from a stream. If the returned vector is empty, the
|
||||
/// stream has reached its end.
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
pub struct ReadReq(pub ReadLimit);
|
||||
pub struct ReadReq {
|
||||
pub limit: ReadLimit,
|
||||
}
|
||||
impl Request for ReadReq {
|
||||
type Response = Result<Vec<u8>, IoError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user