In my code I would like to check if two pointers are pointing to the same location:
...
/// Computes a direct lighting estimate for a single light source sample.
pub fn estimate_direct(...
light: Arc<Light + Send + Sync>,
...
specular: bool)
-> Spectrum {
...
if let Some(light_isect) = scene.intersect(&mut ray) {
found_surface_interaction = true;
if let Some(primitive) = light_isect.primitive {
if let Some(area_light) = primitive.get_area_light() {
// I would like to compare pointers here:
if Arc::ptr_eq(&area_light, &light) {
The error message I get is:
cargo test --release
Compiling pbrt v0.1.11 (file:///home/jan/git/self_hosted/Rust/pbrt)
error[E0308]: mismatched types
--> src/lib.rs:9274:57
|
9274 | if Arc::ptr_eq(&area_light, &light) {
| ^^^^^^ expected trait `AreaLight`, found trait `Light`
|
= note: expected type `&std::sync::Arc<AreaLight + std::marker::Sync + std::marker::Send>`
found type `&std::sync::Arc<Light + std::marker::Sync + std::marker::Send + 'static>`
I'm using inheritance like this:
pub trait Light {
...
}
pub trait AreaLight: Light {
...
}
pub struct DiffuseAreaLight {
...
}
impl DiffuseAreaLight {
...
}
impl Light for DiffuseAreaLight {
...
}
impl AreaLight for DiffuseAreaLight {
...
}
Is this possible somehow? Or where is my thinking going wrong?