Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views on trait objects #26

Merged
merged 6 commits into from
Jun 20, 2024
Merged

Views on trait objects #26

merged 6 commits into from
Jun 20, 2024

Conversation

Mortano
Copy link
Collaborator

@Mortano Mortano commented Jan 11, 2024

Enables point and attribute views on trait objects (e.g. dyn BorrowedBuffer, dyn InterleavedBuffer etc.). This closes a gap in conjunction with the as_interleaved and as_columnar functions on the BorrowedBuffer trait, and makes code like this possible:

fn accepts_any_buffer<'a, B: BorrowedBuffer<'a>>(buffer: &'a B) {
    if let Some(interleaved) = buffer.as_interleaved() {
        for point in interleaved.view::<SimplePoint>().iter() {
            println!("{point:?}");
        }
    } else if let Some(columnar) = buffer.as_columnar() {
        for position in columnar.view_attribute::<Vector3<f64>>(&POSITION_3D).iter() {
            println!("{position}");
        }
    }
}

Also made some traits objects-safe that weren't before.

@Mortano Mortano self-assigned this Jan 11, 2024
@Mortano Mortano merged commit edadc23 into main Jun 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant