-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e6348a
commit 51c9a35
Showing
8 changed files
with
138 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use iof::show; | ||
|
||
fn main() { | ||
// Write a single integer to output. | ||
show!(42); | ||
|
||
// Write a single string to output. | ||
show!("Hello, World!"); | ||
|
||
// Write a vector of integers to output. | ||
show!([1, 2, 3]); | ||
|
||
// Write a matrix of integers to output. | ||
show!([[1, 2, 3], [4, 5, 6]]); | ||
|
||
// Write a matrix of characters to output. | ||
show!([['.', '@', '/'], ['#', '$', '$']]); | ||
|
||
// Write a tuple to output. | ||
show!((1, 2, 3)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
42 | ||
Hello, World! | ||
1 2 3 | ||
1 2 3 | ||
4 5 6 | ||
.@/ | ||
#$$ | ||
1 2 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::{BufReadExt, ReadFrom, ReadFromError}; | ||
use std::fmt::{self, Display}; | ||
|
||
macro_rules! impl_read_into_for_tuple { | ||
($e:ident) => { | ||
use std::convert::Infallible as $e; | ||
impl ReadFrom for () { | ||
type ParseError = $e; | ||
fn try_read_from<S: BufReadExt>(_stream: &mut S) -> Result<(), ReadFromError<Self>> { | ||
Ok(()) | ||
} | ||
} | ||
}; | ||
($e:ident $($t:ident)+) => { | ||
#[derive(Debug)] | ||
pub enum $e<$($t, )+ > { | ||
$($t($t), )+ | ||
} | ||
impl<$($t: std::error::Error, )+ > Display for $e<$($t, )+ > { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { $( Self::$t(err) => Display::fmt(err, f), )+ } | ||
} | ||
} | ||
impl<$($t: std::error::Error, )+ > std::error::Error for $e<$($t, )+ > {} | ||
impl<$($t: ReadFrom, )+> ReadFrom for ( $($t, )+ ) { | ||
type ParseError = $e<$(<$t as ReadFrom>::ParseError, )+>; | ||
fn try_read_from<S: BufReadExt>(stream: &mut S) -> Result<($($t, )+), ReadFromError<Self>> { | ||
Ok(( | ||
$( | ||
<$t as ReadFrom>::try_read_from(stream).map_err(|err| match err { | ||
ReadFromError::<$t>::IOError(e) => ReadFromError::<Self>::IOError(e), | ||
ReadFromError::<$t>::EOF => ReadFromError::<Self>::EOF, | ||
ReadFromError::<$t>::EOL => ReadFromError::<Self>::EOL, | ||
ReadFromError::<$t>::FromStrError(e, s, n) => ReadFromError::<Self>::FromStrError($e::$t(e), s, n), | ||
})?, | ||
)+ | ||
)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_read_into_for_tuple!(Tuple0Error); | ||
impl_read_into_for_tuple!(Tuple1Error T1); | ||
impl_read_into_for_tuple!(Tuple2Error T1 T2); | ||
impl_read_into_for_tuple!(Tuple3Error T1 T2 T3); | ||
impl_read_into_for_tuple!(Tuple4Error T1 T2 T3 T4); | ||
impl_read_into_for_tuple!(Tuple5Error T1 T2 T3 T4 T5); | ||
impl_read_into_for_tuple!(Tuple6Error T1 T2 T3 T4 T5 T6); | ||
impl_read_into_for_tuple!(Tuple7Error T1 T2 T3 T4 T5 T6 T7); | ||
impl_read_into_for_tuple!(Tuple8Error T1 T2 T3 T4 T5 T6 T7 T8); | ||
impl_read_into_for_tuple!(Tuple9Error T1 T2 T3 T4 T5 T6 T7 T8 T9); | ||
impl_read_into_for_tuple!(Tuple10Error T1 T2 T3 T4 T5 T6 T7 T8 T9 T10); | ||
impl_read_into_for_tuple!(Tuple11Error T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11); | ||
impl_read_into_for_tuple!(Tuple12Error T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters