rust_codegen/
associated_type.rs

1use crate::bound::Bound;
2use crate::r#type::Type;
3
4/// Defines an associated type.
5#[derive(Debug, Clone)]
6pub struct AssociatedType(pub Bound);
7
8impl AssociatedType {
9    /// Add a bound to the associated type.
10    /// 
11    /// # Arguments
12    /// 
13    /// * `ty` - The associated type's bound.
14    /// 
15    /// # Examples
16    /// 
17    /// ```
18    /// use rust_codegen::{AssociatedType, Trait};
19    /// 
20    /// let mut trait_foo = Trait::new("Foo");
21    /// let mut trait_bar = Trait::new("Bar");
22    /// 
23    /// trait_bar.associated_type("A").bound("Foo");
24    /// ```
25    pub fn bound<T>(&mut self, ty: T) -> &mut Self
26    where
27        T: Into<Type>,
28    {
29        self.0.bound.push(ty.into());
30        self
31    }
32}