Skip to main content

forge_doc/writer/
traits.rs

1//! Helper traits for writing documentation.
2
3use crate::ParamInfo;
4
5/// Helper trait to abstract over a type that can be documented as a parameter.
6pub(crate) trait ParamLike {
7    /// Returns the type as a string.
8    fn type_name(&self) -> &str;
9
10    /// Returns the identifier of the parameter.
11    fn name(&self) -> Option<&str>;
12}
13
14impl ParamLike for ParamInfo {
15    fn type_name(&self) -> &str {
16        &self.ty
17    }
18
19    fn name(&self) -> Option<&str> {
20        self.name.as_deref()
21    }
22}
23
24impl<T> ParamLike for &T
25where
26    T: ParamLike,
27{
28    fn type_name(&self) -> &str {
29        T::type_name(*self)
30    }
31
32    fn name(&self) -> Option<&str> {
33        T::name(*self)
34    }
35}