Skip to content

Commit

Permalink
Move most important type to top of module
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed May 24, 2024
1 parent 40a85af commit 3c09fe5
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions crates/fj-core/src/validate/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ use std::{any::type_name_of_val, collections::HashMap, fmt};

use crate::storage::Handle;

/// Object that should be exclusively owned by another, is not
///
/// Some objects are expected to be "owned" by a single other object. This means
/// that only one reference to these objects must exist within the topological
/// object graph.
#[derive(Clone, Debug, thiserror::Error)]
pub struct ObjectNotExclusivelyOwned<T, U> {
object: Handle<T>,
referenced_by: Vec<Handle<U>>,
}

impl<T, U> fmt::Display for ObjectNotExclusivelyOwned<T, U>
where
T: fmt::Debug,
U: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"`{}` ({:?}) referenced by multiple `{}` objects ({:?})",
type_name_of_val(&self.object),
self.object,
type_name_of_val(&self.referenced_by),
self.referenced_by
)
}
}

#[derive(Default)]
pub struct ReferenceCounter<T, U>(HashMap<Handle<T>, Vec<Handle<U>>>);

Expand Down Expand Up @@ -38,31 +66,3 @@ macro_rules! validate_references {
)*
};
}

/// Object that should be exclusively owned by another, is not
///
/// Some objects are expected to be "owned" by a single other object. This means
/// that only one reference to these objects must exist within the topological
/// object graph.
#[derive(Clone, Debug, thiserror::Error)]
pub struct ObjectNotExclusivelyOwned<T, U> {
object: Handle<T>,
referenced_by: Vec<Handle<U>>,
}

impl<T, U> fmt::Display for ObjectNotExclusivelyOwned<T, U>
where
T: fmt::Debug,
U: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"`{}` ({:?}) referenced by multiple `{}` objects ({:?})",
type_name_of_val(&self.object),
self.object,
type_name_of_val(&self.referenced_by),
self.referenced_by
)
}
}

0 comments on commit 3c09fe5

Please sign in to comment.