我在文件中有2个trait实现。我该如何从first_function
的第二个实现中调用Trait
?
impl<T: Trait> Module<T> {
pub fn first_function() {
// some code here
}
}
impl<T: Trait> Second<T::SomeType> for Module<T> {
pub fn second_function() {
// Needs to call the first function available in first trait implementation.
}
}
答案 0 :(得分:1)
您需要使用turbofish(const float borderWidth = 8.0f;
Pen borderPen = new Pen(Color.Red, borderWidth) { Alignment = System.Drawing.Drawing2D.PenAlignment.Inset };
public Form2()
{
InitializeComponent();
this.Paint += Form2_Paint;
this.Resize += Form2_Resize;
}
private void Form2_Resize(object sender, EventArgs e)
{
Invalidate();
}
private void Form2_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(borderPen, this.ClientRectangle);
}
)语法:
::<>
完整示例:
Module::<T>::first_function()
另请参阅有关turbofish语法的以下相关问题: