pub trait SoaExtractable: Agent {
// Required methods
fn num_columns() -> usize;
fn column_names() -> Vec<&'static str>;
fn extract_row(&self, columns: &mut [Vec<f32>]);
fn write_back_row(&mut self, columns: &[&[f32]], row: usize);
}Expand description
Trait for agents whose numeric fields can be extracted into SoA buffers and written back from SoA buffers after GPU computation.
Each “column” is a Vec<f32> representing one field across all agents.
The order of agents in the buffers matches the order of IDs returned
by extract.
§Example
ⓘ
impl SoaExtractable for Particle {
fn num_columns() -> usize { 2 } // x, vx
fn column_names() -> Vec<&'static str> { vec!["x", "vx"] }
fn extract_row(&self, columns: &mut [Vec<f32>]) {
columns[0].push(self.x);
columns[1].push(self.vx);
}
fn write_back_row(&mut self, columns: &[&[f32]], row: usize) {
self.x = columns[0][row];
self.vx = columns[1][row];
}
}Required Methods§
Sourcefn num_columns() -> usize
fn num_columns() -> usize
Number of f32 columns to extract.
Sourcefn column_names() -> Vec<&'static str>
fn column_names() -> Vec<&'static str>
Human-readable names for each column (for debugging / PTX variable naming).
Sourcefn extract_row(&self, columns: &mut [Vec<f32>])
fn extract_row(&self, columns: &mut [Vec<f32>])
Push this agent’s values into the column vectors.
Sourcefn write_back_row(&mut self, columns: &[&[f32]], row: usize)
fn write_back_row(&mut self, columns: &[&[f32]], row: usize)
Read this agent’s values back from the column slices at row.
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.