Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Make BlockStore usable as a trait object #518

Merged
merged 1 commit into from
Mar 20, 2019

Conversation

edolstra
Copy link
Contributor

This requires getting rid of the generic type parameter in get_path_to_nth_ancestor(), dropping the Self return type in iterate_range() and dropping Sized.

This requires getting rid of the generic type parameter in
get_path_to_nth_ancestor(), dropping the Self return type in
iterate_range() and dropping Sized.
to_depth: to_info.depth,
cur_depth: to_info.depth - distance,
pending_infos: vec![to_info],
})
}
}
}

// See https://stackoverflow.com/questions/42121299/provided-method-casting-self-to-trait-object
fn as_trait(&self) -> &BlockStore<Block = Self::Block>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there were a few other solutions that don't require a bogus method. I'd go with a helper blanket-implemented trait.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you meant something like:

pub trait BlockStore {
  fn as_trait(&self) -> &BlockStore<Block = Self::Block> { self }
}

would that work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work since self is not Sized, and adding a Sized bound to as_trait makes it unavailable in trait objects.

@vincenthz vincenthz merged commit c1ec588 into input-output-hk:master Mar 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants