pub struct TypeBound {
pub param_name: String,
pub constraint: BoundConstraint,
}Expand description
A type bound that constrains a type parameter.
Type bounds allow specifying constraints on type parameters, such as:
T: Comparable- T must be a comparable typeT: Numeric- T must be a numeric typeT: Subtypes(Person)- T must be a subtype of Person
Fields§
§param_name: StringThe name of the type parameter being constrained
constraint: BoundConstraintThe constraint kind
Implementations§
Source§impl TypeBound
impl TypeBound
Sourcepub fn new(param_name: impl Into<String>, constraint: BoundConstraint) -> Self
pub fn new(param_name: impl Into<String>, constraint: BoundConstraint) -> Self
Creates a new type bound with the given constraint.
Sourcepub fn subtype(
param_name: impl Into<String>,
supertype: impl Into<String>,
) -> Self
pub fn subtype( param_name: impl Into<String>, supertype: impl Into<String>, ) -> Self
Creates a subtype bound: T: Subtypes(supertype)
Sourcepub fn trait_bound(
param_name: impl Into<String>,
trait_name: impl Into<String>,
) -> Self
pub fn trait_bound( param_name: impl Into<String>, trait_name: impl Into<String>, ) -> Self
Creates a trait bound: T: Trait(trait_name)
Sourcepub fn comparable(param_name: impl Into<String>) -> Self
pub fn comparable(param_name: impl Into<String>) -> Self
Creates a comparable bound: T: Comparable
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypeBound
impl<'de> Deserialize<'de> for TypeBound
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for TypeBound
impl StructuralPartialEq for TypeBound
Auto Trait Implementations§
impl Freeze for TypeBound
impl RefUnwindSafe for TypeBound
impl Send for TypeBound
impl Sync for TypeBound
impl Unpin for TypeBound
impl UnwindSafe for TypeBound
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.