Closed
Description
We currently have an assist to generate a delegate method for a field and an assist to generate a deref implementation towards a field. I believe we can generalize the latter by generating a "delegated trait impl" to a field, which would include generating a deref impl for a field but also other things like Intoiterator
etc
$0 marks the cursor
pub(crate) struct RibStack<R> {
$0ribs: Vec<R>,
used: usize,
}
Should offer delegating traits impls implemented by Vec<R>
, resulting in output like the following:
impl<R> std::ops::Deref for RibStack<R> {
type Target = <Vec<R> as std::ops::Deref>::Target;
fn deref(&self) -> &Self::Target {
&self.ribs // note that for deref we should special case emitting `&self.field` instead of `self.field.deref()`/`Deref::deref(&self.field)`
}
}
impl<R> std::ops::DerefMut for RibStack<R> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.ribs // note that for deref we should special case emitting `&mut self.field` instead of `self.field.deref_mut()`/`DerefMut::deref_mut(&mut self.field)`
}
}
impl<R> IntoIterator for RibStack<R> {
type Item = <Vec<R> as IntoIterator>::Item;
type IntoIter = <Vec<R> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
IntoIterator::into_iter(self.ribs)
}
}