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