在传统的面向对象语言(例如Java)中,可以通过从重写版本中的超类调用原始方法来"扩展"继承类中方法的功能,例如:
class A {
public void method() {
System.out.println("I am doing some serious stuff!");
}
}
class B extends A {
@Override
public void method() {
super.method(); // here we call the original version
System.out.println("And I'm doing something more!");
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,在Java中,我可以使用super关键字从超类中调用原始版本.我能够获得继承特征的等效行为,但在实现结构的特征时却没有.
trait Foo {
fn method(&self) {
println!("default implementation");
}
}
trait Boo: Foo {
fn method(&self) {
// this is overriding the default implementation
Foo::method(self); // here, we successfully call the original
// this is tested …Run Code Online (Sandbox Code Playgroud) 我正在开发一个小游戏开发库。该库的元素之一是 Canvas(屏幕外绘图区),它是通过 OpenGL 帧缓冲区实现的。到目前为止,一切都很好,我生成了一个纹理,将它附加到帧缓冲区,渲染到它,然后使用帧缓冲区的纹理作为 Texture2D。
现在,我想向我的库中添加抗锯齿功能,因此我希望能够在 Canvas 上设置多重采样。现在我很困惑,因为我发现您需要更改着色器以使用多样本纹理等等。
那么,我应该怎么做才能为我的帧缓冲区启用多重采样,以便我尽量减少对库的其余代码的更改?如果可能,我只想将渲染结果用作常规 Texture2D。
我刚开始学习Rust一点,我遇到了这个问题,我无法解决.
在Rust中,std :: num :: Float trait(以及其他特性)中有静态方法,它们不带参数.那没关系,但我发现他们无法打电话.我试过这些选项:
Float::epsilon() // complains that "type annotations required"
Float::<f32>::epsilon() // complains "too many type parameters provided"
Float::epsilon::<f32>() // same thing as the previous one
f32::epsilon() // I'd love this syntax to work, but it doesn't
Run Code Online (Sandbox Code Playgroud)
有没有人解决这个问题?难道只是我是愚蠢的,或者这是Rust内部的真正问题?
rust ×2
antialiasing ×1
default ×1
framebuffer ×1
generics ×1
inheritance ×1
methods ×1
oop ×1
opengl ×1
static ×1
traits ×1