Is there a way to forward docstring declarations to wrapper?

I would like to know if it is possible to take the docstrings of an underlying function that I am wrapping and include them in the outer wrapping function's docstrings.

For example, let's suppose I want to create a wrapper for the Vec struct, the only difference being that for every function call, I always println something.

For example, I might have something like this:

struct SuperVec<T>(Vec<T>)

impl<T> for SuperVec<T> {
  fn new() -> Self {
    println!("You just called new! Good for you!");
    SuperVec(Vec::new())
  }
}

A struct like a Vec has many functions, and while wrapping them is easy enough, copying/pasting all of the docstrings is quite difficult. I wanted to know if there is a way to do something like:

impl<T> for SuperVec<T> {

  /// @include Vec::new 
  fn new() -> Self {
    // ......
  }
}

that would automatically paste the current docstrings for the Vec::new function that I am wrapping and add them to the new function for SuperVec.

Please let me know. If not, perhaps it would be worth it for me to write an RFC (although I have never done it before), if other people were interested.

Note that using Deref and DerefMut you can allow using all the methods on Vec without wrapping every one.

If I understand correctly, I do not think that would help because I do not just want to invoke the deref target's Vec methods as they are exactly, I want to also have a custom println message for each different method.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.