pub trait MulTE<T, E> {
// Required method
fn mul(a: &T, b: &E) -> E;
}Expand description
通过这个trait中的mul函数实现T和E类型相乘
如果需要使用自己定义的数据类型,则需要实现这个trait,如
use network_flow::graph::Graph;
use network_flow::costtype::MulTE;
#[derive(Default, Clone)]
struct Complex {
x : f64,
y : f64
}
struct Mul_u32_Complex;
impl MulTE<u32, Complex> for Mul_u32_Complex {
fn mul(a : &u32, b : &Complex) -> Complex {
Complex {
x : *a as f64 * b.x,
y : *a as f64 * b.y
}
}
}
let x = Graph::<String, u32, Complex, Mul_u32_Complex>::new();Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.