Struct php_codegen::parameter::Parameter
source · pub struct Parameter {
pub attributes: Vec<AttributeGroup>,
pub name: String,
pub data_type: Option<DataType>,
pub default: Option<Value>,
pub modifiers: Vec<Modifier>,
pub visibility: Option<VisibilityModifier>,
pub variadic: bool,
}Fields§
§attributes: Vec<AttributeGroup>§name: String§data_type: Option<DataType>§default: Option<Value>§modifiers: Vec<Modifier>§visibility: Option<VisibilityModifier>§variadic: boolImplementations§
source§impl Parameter
impl Parameter
sourcepub fn new<T: ToString>(name: T) -> Self
pub fn new<T: ToString>(name: T) -> Self
Examples found in repository?
examples/simple.rs (line 21)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let file = File::new()
.namespaced("App")
.declare("strict_types", 1)
.function(
Function::new("format")
.document(
Document::new()
.text("Format a string with the given arguments using sprintf.")
.empty_line()
.tag("param", "non-empty-string $template")
.empty_line()
.simple_tag("pure"),
)
.parameter(Parameter::new("template").typed(DataType::String))
.parameter(
Parameter::new("args")
.variadic()
.typed(DataType::Union(vec![
DataType::Integer,
DataType::Float,
DataType::String,
DataType::Null,
])),
)
.returns(DataType::String)
.body(vec![
"return sprintf($template, ...array_map(",
" static fn ($arg) => is_float($arg) ? number_format($arg, 2) : $arg,",
" array_filter($args, static fn ($arg) => $arg !== null)",
"));",
]),
);
print!("{file}");
}pub fn attributes(self, attributes: AttributeGroup) -> Self
sourcepub fn typed(self, data_type: DataType) -> Self
pub fn typed(self, data_type: DataType) -> Self
Examples found in repository?
examples/simple.rs (line 21)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let file = File::new()
.namespaced("App")
.declare("strict_types", 1)
.function(
Function::new("format")
.document(
Document::new()
.text("Format a string with the given arguments using sprintf.")
.empty_line()
.tag("param", "non-empty-string $template")
.empty_line()
.simple_tag("pure"),
)
.parameter(Parameter::new("template").typed(DataType::String))
.parameter(
Parameter::new("args")
.variadic()
.typed(DataType::Union(vec![
DataType::Integer,
DataType::Float,
DataType::String,
DataType::Null,
])),
)
.returns(DataType::String)
.body(vec![
"return sprintf($template, ...array_map(",
" static fn ($arg) => is_float($arg) ? number_format($arg, 2) : $arg,",
" array_filter($args, static fn ($arg) => $arg !== null)",
"));",
]),
);
print!("{file}");
}sourcepub fn variadic(self) -> Self
pub fn variadic(self) -> Self
Examples found in repository?
examples/simple.rs (line 24)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let file = File::new()
.namespaced("App")
.declare("strict_types", 1)
.function(
Function::new("format")
.document(
Document::new()
.text("Format a string with the given arguments using sprintf.")
.empty_line()
.tag("param", "non-empty-string $template")
.empty_line()
.simple_tag("pure"),
)
.parameter(Parameter::new("template").typed(DataType::String))
.parameter(
Parameter::new("args")
.variadic()
.typed(DataType::Union(vec![
DataType::Integer,
DataType::Float,
DataType::String,
DataType::Null,
])),
)
.returns(DataType::String)
.body(vec![
"return sprintf($template, ...array_map(",
" static fn ($arg) => is_float($arg) ? number_format($arg, 2) : $arg,",
" array_filter($args, static fn ($arg) => $arg !== null)",
"));",
]),
);
print!("{file}");
}