pub struct Function {
    pub documentation: Option<Document>,
    pub attributes: Vec<AttributeGroup>,
    pub name: String,
    pub parameters: Vec<Parameter>,
    pub return_type: Option<DataType>,
    pub body: Body,
}

Fields§

§documentation: Option<Document>§attributes: Vec<AttributeGroup>§name: String§parameters: Vec<Parameter>§return_type: Option<DataType>§body: Body

Implementations§

Examples found in repository?
examples/simple.rs (line 12)
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}");
}
Examples found in repository?
examples/simple.rs (lines 13-20)
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}");
}
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}");
}
Examples found in repository?
examples/simple.rs (line 32)
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}");
}
Examples found in repository?
examples/simple.rs (lines 33-38)
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}");
}

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.