[DEV-7084] TAMER: Correct Ix trait bound for AsgError
The `Debug` bound is inconvenient and requires propagation to any types that use it. Further, it's really awkward having `Display` depend on `Debug`; if we want to render a useful display here, we can write one. To be clear: IndexType implements Debug. For now, this is pretty-printed by another part of the code, which we don't want to implement in `Display` because it requires looking things up from the graph.master
parent
cfc13f9016
commit
ef79a763ac
|
@ -212,19 +212,13 @@ impl<Ix: IndexType> ObjectRef<Ix> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Ix> From<NodeIndex<Ix>> for ObjectRef<Ix>
|
||||
where
|
||||
Ix: IndexType,
|
||||
{
|
||||
impl<Ix: IndexType> From<NodeIndex<Ix>> for ObjectRef<Ix> {
|
||||
fn from(index: NodeIndex<Ix>) -> Self {
|
||||
Self(index)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ix> From<ObjectRef<Ix>> for NodeIndex<Ix>
|
||||
where
|
||||
Ix: IndexType,
|
||||
{
|
||||
impl<Ix: IndexType> From<ObjectRef<Ix>> for NodeIndex<Ix> {
|
||||
fn from(objref: ObjectRef<Ix>) -> Self {
|
||||
objref.0
|
||||
}
|
||||
|
@ -246,7 +240,7 @@ pub type Node<O> = Option<O>;
|
|||
/// so this stores only owned values.
|
||||
/// The caller will know the problem values.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum AsgError<Ix: Debug> {
|
||||
pub enum AsgError<Ix: IndexType> {
|
||||
/// An object could not change state in the manner requested.
|
||||
///
|
||||
/// See [`Asg::declare`] and [`Asg::set_fragment`] for more
|
||||
|
@ -261,21 +255,19 @@ pub enum AsgError<Ix: Debug> {
|
|||
Cycles(Vec<Vec<ObjectRef<Ix>>>),
|
||||
}
|
||||
|
||||
impl<Ix: Debug> std::fmt::Display for AsgError<Ix> {
|
||||
impl<Ix: IndexType> std::fmt::Display for AsgError<Ix> {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::ObjectTransition(err) => std::fmt::Display::fmt(&err, fmt),
|
||||
Self::UnexpectedNode(msg) => {
|
||||
write!(fmt, "unexpected node: {}", msg)
|
||||
}
|
||||
Self::Cycles(cycles) => {
|
||||
write!(fmt, "Cyclic dependencies detected: {:?}", cycles)
|
||||
}
|
||||
Self::Cycles(_) => write!(fmt, "cyclic dependencies"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ix: Debug> std::error::Error for AsgError<Ix> {
|
||||
impl<Ix: IndexType> std::error::Error for AsgError<Ix> {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::ObjectTransition(err) => err.source(),
|
||||
|
@ -284,7 +276,7 @@ impl<Ix: Debug> std::error::Error for AsgError<Ix> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Ix: Debug> From<TransitionError> for AsgError<Ix> {
|
||||
impl<Ix: IndexType> From<TransitionError> for AsgError<Ix> {
|
||||
fn from(err: TransitionError) -> Self {
|
||||
Self::ObjectTransition(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue