Macro scad_generator::qstruct
[−]
[src]
macro_rules! qstruct { ($name:ident ($($param_name:ident: $param_type:ty),*$(),+) { $($mem_name:ident : $mem_type:ty = $mem_value:expr),*$(),+ }) => { ... }; }
Used to create structs with ::new functions that set default values without having to write an impl for new.
This exists because a lot of times when making scad models, you want to
have a lot of parameters with fixed values. qstruct!
also supports adding
parameters to the new
function of the struct for the members that should
be changeable.
Usage
The qstruct starts with the name of the resulting struct, followed by a
list of parameters to the new()
function inside ()
. After that, the member
variables are listed inside {}
and separated by ,
. Each member should
have a name, followed by the
type followed by the value. The value is any valid rust expression and can contain
any variables that are in the struct, or parameters to the new function.
qstruct!(Demo(inner_width: f32) { //Constant value shell_thickness: f32 = 1., //Value based on function parameter outer_width: f32 = inner_width + shell_thickness, //Value that depends on another member outer_height: f32 = outer_width / 2., }); //Add your own functions to the struct impl Demo { pub fn get_outer(&self) -> ScadObject { scad!(Cube(vec3(self.outer_width, self.outer_width, self.outer_height))) } } Run