This commit is contained in:
AF 2023-06-16 07:33:32 +00:00
parent 5081166bca
commit 5cbabbdb37
15 changed files with 98 additions and 100 deletions

View File

@ -13,7 +13,7 @@ struct AvlN<A> {
impl<A: Display> Display for AvlN<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("({} {} {})", self.l, self.key, self.r))
write!(f, "({} {} {})", self.l, self.key, self.r)
}
}
@ -39,7 +39,7 @@ impl<A> Clone for AvlR<A> {
impl<A: Display> Display for AvlR<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.node))
write!(f, "{}", self.node)
}
}
@ -67,8 +67,8 @@ impl<A> Clone for AvlT<A> {
impl<A: Display> Display for AvlT<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.reference {
Some(reference) => f.write_fmt(format_args!("{}", reference)),
None => f.write_fmt(format_args!("-")),
Some(reference) => write!(f, "{}", reference),
None => write!(f, "-"),
}
}
}

View File

@ -43,7 +43,7 @@ where
UnbalancedReference<'a, T, A>: std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("({} {} {})", self.cl, self.key, self.cr))
write!(f, "({} {} {})", self.cl, self.key, self.cr)
}
}
@ -53,15 +53,15 @@ where
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UnbalancedTree::Leaf => f.write_fmt(format_args!(".")),
UnbalancedTree::Node(reference) => f.write_fmt(format_args!("{}", reference)),
UnbalancedTree::Leaf => write!(f, "."),
UnbalancedTree::Node(reference) => write!(f, "{}", reference),
}
}
}
impl<'a, A: 'a + Display> Display for UnbalancedReference<'a, instances::solo::SoloInstance, A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.0()))
write!(f, "{}", self.0())
}
}
@ -70,8 +70,8 @@ impl<'a, A: 'a + Display> Display
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0() {
Ok(node) => f.write_fmt(format_args!("{}", node)),
Err(()) => f.write_fmt(format_args!("~")),
Ok(node) => write!(f, "{}", node),
Err(()) => write!(f, "~"),
}
}
}

View File

@ -19,7 +19,7 @@ use crate::rcore::*;
impl Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}@{}", hex::encode(self.point), self.index))
write!(f, "{}@{}", hex::encode(self.point), self.index)
}
}

View File

@ -17,10 +17,11 @@ pub enum IntParseError {
impl Display for IntParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Eof => f.write_fmt(format_args!("encountered EOF write parsing an integer.")),
Self::ExtraData(length) => f.write_fmt(format_args!(
Self::Eof => write!(f, "encountered EOF write parsing an integer."),
Self::ExtraData(length) => write!(
f,
"encountered extra data of length {length} while parsing an integer.",
)),
),
}
}
}

View File

@ -22,12 +22,13 @@ impl Display for BooleanParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::OutOfBounds(value) => {
f.write_fmt(format_args!("boolean value out of bounds: {}.", value))
write!(f, "boolean value out of bounds: {}.", value)
}
Self::Eof => f.write_fmt(format_args!("encountered EOF write parsing a boolean.")),
Self::ExtraData(length) => f.write_fmt(format_args!(
Self::Eof => write!(f, "encountered EOF write parsing a boolean."),
Self::ExtraData(length) => write!(
f,
"encountered extra data of length {length} while parsing a boolean.",
)),
),
}
}
}

View File

@ -41,22 +41,22 @@ impl<'a> Display for CastError<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CastError::Typeless(typeless_error) => {
f.write_fmt(format_args!("typeless cast error: {}", typeless_error))
write!(f, "typeless cast error: {}", typeless_error)
}
CastError::AddressIndexOutOfBounds { index, length } => {
write!(f, "cast index out of bound: {}>={}", index, length)
}
CastError::AddressIndexOutOfBounds { index, length } => f.write_fmt(format_args!(
"cast index out of bound: {}>={}",
index, length
)),
CastError::AddressPointMismatch {
expected,
received,
index,
} => f.write_fmt(format_args!(
} => write!(
f,
"address mismatch at index {}: {}>={}",
index,
hex::encode(expected),
hex::encode(received),
)),
),
}
}
}

View File

@ -39,23 +39,23 @@ impl<E: Display> Display for AvlError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Int(int_error) => {
f.write_fmt(format_args!("failed to parse AVL tree height: {int_error}"))
write!(f, "failed to parse AVL tree height: {int_error}")
}
Self::Point(point_error) => {
write!(f, "failed to parse AVL node reference: {point_error}")
}
Self::Point(point_error) => f.write_fmt(format_args!(
"failed to parse AVL node reference: {point_error}"
)),
Self::Key(key_error) => {
f.write_fmt(format_args!("failed to parse AVL node key: {key_error}"))
write!(f, "failed to parse AVL node key: {key_error}")
}
Self::NodeHeight => f.write_fmt(format_args!("invalid AVL non-leaf height: 0.")),
Self::NodeHeight => write!(f, "invalid AVL non-leaf height: 0."),
Self::LeafHeight(height) => {
f.write_fmt(format_args!("invalid AVL leaf height: {height}!=0."))
write!(f, "invalid AVL leaf height: {height}!=0.")
}
Self::Balance(hl, hr) => write!(f, "unbalanced AVL node: {hl} {hr}."),
Self::HeightOverflow => write!(f, "AVL tree height overflow"),
Self::HeightMismatch { child, parent } => {
write!(f, "AVL child-parent height mismatch: {child:?}, {parent}")
}
Self::Balance(hl, hr) => f.write_fmt(format_args!("unbalanced AVL node: {hl} {hr}.")),
Self::HeightOverflow => f.write_fmt(format_args!("AVL tree height overflow")),
Self::HeightMismatch { child, parent } => f.write_fmt(format_args!(
"AVL child-parent height mismatch: {child:?}, {parent}"
)),
}
}
}

View File

@ -37,14 +37,12 @@ pub enum PairParseError<ErrorA: Error, ErrorB: Error> {
impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PairParseError::A(error) => f.write_fmt(format_args!(
"error while parsing first element of a pair: {}",
error
)),
PairParseError::B(error) => f.write_fmt(format_args!(
"error while parsing first element of a pair: {}",
error
)),
PairParseError::A(error) => {
write!(f, "error while parsing first element of a pair: {}", error)
}
PairParseError::B(error) => {
write!(f, "error while parsing second element of a pair: {}", error)
}
}
}
}

View File

@ -57,11 +57,11 @@ pub enum StackParseError<ElementParseError: Error> {
impl<ElementParseError: Error> Display for StackParseError<ElementParseError> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StackParseError::Point(ppe) => {
f.write_fmt(format_args!("can't parse stack's next pointer: {}", ppe))
Self::Point(ppe) => {
write!(f, "can't parse stack's next pointer: {}", ppe)
}
StackParseError::Element(epe) => {
f.write_fmt(format_args!("can't parse stack's element: {}", epe))
Self::Element(epe) => {
write!(f, "can't parse stack's element: {}", epe)
}
}
}

View File

@ -96,10 +96,11 @@ pub struct SizeError {
impl Display for SizeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
write!(
f,
"expected {} bytes, read/wrote {} instead.",
self.expected, self.received
))
)
}
}
@ -115,9 +116,9 @@ pub enum CheckedParseError<P: Error> {
impl<P: Error> Display for CheckedParseError<P> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CheckedParseError::Parse(parse_error) => f.write_fmt(format_args!("{}", parse_error)),
CheckedParseError::Size(size_error) => {
f.write_fmt(format_args!("size check failed: {}", size_error))
Self::Parse(parse_error) => write!(f, "{}", parse_error),
Self::Size(size_error) => {
write!(f, "size check failed: {}", size_error)
}
}
}

View File

@ -41,10 +41,9 @@ pub enum PointParseError {
impl Display for PointParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PointParseError::WrongLength(length) => f.write_fmt(format_args!(
"expected {} bytes, received {}.",
HASH_SIZE, length
)),
Self::WrongLength(length) => {
write!(f, "expected {} bytes, received {}.", HASH_SIZE, length)
}
}
}
}

View File

@ -4,16 +4,16 @@ use super::*;
impl<A: Display> Display for WithLengthAndWidth<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.value()))
write!(f, "{}", self.value())
}
}
impl Display for RenderedAny {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Common(common) => f.write_fmt(format_args!("{}", common)),
Self::Wide(vec) => f.write_fmt(format_args!("( {} )", RenderVec(vec))),
Self::Long(vec) => f.write_fmt(format_args!("( {} )", RenderVec(vec))),
Self::Common(common) => write!(f, "{}", common),
Self::Wide(vec) => write!(f, "( {} )", RenderVec(vec)),
Self::Long(vec) => write!(f, "( {} )", RenderVec(vec)),
}
}
}
@ -21,10 +21,10 @@ impl Display for RenderedAny {
impl Display for RenderedCommon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Empty => f.write_fmt(format_args!(".")),
Self::Resolution => f.write_fmt(format_args!("?")),
Self::Event(event) => f.write_fmt(format_args!("{}", event)),
Self::Action { name, rendered } => f.write_fmt(format_args!("{} @ {}", name, rendered)),
Self::Empty => write!(f, "."),
Self::Resolution => write!(f, "?"),
Self::Event(event) => write!(f, "{}", event),
Self::Action { name, rendered } => write!(f, "{} @ {}", name, rendered),
}
}
}
@ -36,11 +36,11 @@ impl Display for RenderVec<&Vec<WithLengthAndWidth<RenderedWide>>> {
let mut delimiter = "";
let mut tail = "~";
for rendered in self.0 {
f.write_fmt(format_args!("{}{}", delimiter, rendered))?;
write!(f, "{}{}", delimiter, rendered)?;
delimiter = " > ";
tail = "";
}
f.write_fmt(format_args!("{}", tail))
write!(f, "{}", tail)
}
}
@ -49,19 +49,19 @@ impl Display for RenderVec<&Vec<WithLengthAndWidth<RenderedLong>>> {
let mut delimiter = "";
let mut tail = "~";
for rendered in self.0 {
f.write_fmt(format_args!("{}{}", delimiter, rendered))?;
write!(f, "{}{}", delimiter, rendered)?;
delimiter = " | ";
tail = "";
}
f.write_fmt(format_args!("{}", tail))
write!(f, "{}", tail)
}
}
impl Display for RenderedLong {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Common(common) => f.write_fmt(format_args!("{}", common)),
Self::Long(vec) => f.write_fmt(format_args!("( {} )", RenderVec(vec))),
Self::Common(common) => write!(f, "{}", common),
Self::Long(vec) => write!(f, "( {} )", RenderVec(vec)),
}
}
}
@ -69,8 +69,8 @@ impl Display for RenderedLong {
impl Display for RenderedWide {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Common(common) => f.write_fmt(format_args!("{}", common)),
Self::Wide(vec) => f.write_fmt(format_args!("( {} )", RenderVec(vec))),
Self::Common(common) => write!(f, "{}", common),
Self::Wide(vec) => write!(f, "( {} )", RenderVec(vec)),
}
}
}

View File

@ -21,20 +21,18 @@ impl Trace {
fn fmt_parallel(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Trace::Parallel(a, b) => {
f.write_fmt(format_args!("{} | {}", ParallelBox(a), ParallelBox(b)))
write!(f, "{} | {}", ParallelBox(a), ParallelBox(b))
}
trace => f.write_fmt(format_args!("{}", trace)),
trace => write!(f, "{}", trace),
}
}
fn fmt_sequential(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Trace::Sequential { first, second } => f.write_fmt(format_args!(
"{} > {}",
SequentialBox(first),
SequentialBox(second)
)),
trace => f.write_fmt(format_args!("{}", trace)),
Trace::Sequential { first, second } => {
write!(f, "{} > {}", SequentialBox(first), SequentialBox(second))
}
trace => write!(f, "{}", trace),
}
}
}
@ -58,25 +56,26 @@ impl<'a> Display for SequentialBox<'a> {
impl Display for Trace {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Trace::Pure => f.write_fmt(format_args!(".")),
Trace::InvolvesOneResolution => f.write_fmt(format_args!("?")),
Trace::Event(event) => f.write_fmt(format_args!("{}", event)),
Trace::Wrapped { name, trace } => f.write_fmt(format_args!("{} @ {}", name, trace)),
Trace::Parallel(a, b) => {
f.write_fmt(format_args!("( {} | {} )", ParallelBox(a), ParallelBox(b)))
Self::Pure => write!(f, "."),
Self::InvolvesOneResolution => write!(f, "?"),
Self::Event(event) => write!(f, "{}", event),
Self::Wrapped { name, trace } => write!(f, "{} @ {}", name, trace),
Self::Parallel(a, b) => {
write!(f, "( {} | {} )", ParallelBox(a), ParallelBox(b))
}
Trace::Sequential { first, second } => f.write_fmt(format_args!(
Self::Sequential { first, second } => write!(
f,
"( {} > {} )",
SequentialBox(first),
SequentialBox(second)
)),
),
}
}
}
impl Display for TraceBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.trace))
write!(f, "{}", self.trace)
}
}

View File

@ -84,7 +84,7 @@ pub struct TypelessError<'a>(Box<dyn 'a + Error>);
impl<'a> Display for TypelessError<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("typeless error: {}", self.0))
write!(f, "typeless error: {}", self.0)
}
}

View File

@ -50,16 +50,15 @@ impl<'a> From<CastError<'a>> for TestLookupError<'a> {
impl<'a> Display for TestLookupError<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TestLookupError::Typeless(typeless_error) => {
f.write_fmt(format_args!("typeless lookup failure: {}", typeless_error))
Self::Typeless(typeless_error) => {
write!(f, "typeless lookup failure: {}", typeless_error)
}
TestLookupError::Cast(cast_error) => {
f.write_fmt(format_args!("cast failure: {}", cast_error))
Self::Cast(cast_error) => {
write!(f, "cast failure: {}", cast_error)
}
Self::EmptyResolverAccess(address) => {
write!(f, "accessed an empty resolved at address {}.", address)
}
TestLookupError::EmptyResolverAccess(address) => f.write_fmt(format_args!(
"accessed an empty resolved at address {}.",
address
)),
}
}
}