Skip to content

Commit

Permalink
Implement heapsize::HeapSizeOf for FileId
Browse files Browse the repository at this point in the history
We can't derive this automatically as `HeapSizeOf` doesn't know about
`NonZeroU32`
  • Loading branch information
etaoins committed Jan 5, 2020
1 parent edd0e94 commit 11f3c18
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion codespan/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ impl fmt::Display for SpanOutOfBoundsError {
/// A handle that points to a file in the database.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "memory_usage", derive(heapsize_derive::HeapSizeOf))]
pub struct FileId(NonZeroU32);

// `HeapSizeOf` isn't implemented for `NonZeroU32` and we can't add it due to trait orphan rules
#[cfg(feature = "memory_usage")]
impl heapsize::HeapSizeOf for FileId {
fn heap_size_of_children(&self) -> usize {
0
}
}

impl FileId {
/// Offset of our `FileId`'s numeric value to an index on `Files::files`.
///
Expand Down

0 comments on commit 11f3c18

Please sign in to comment.