pub struct ComponentCompiler { /* private fields */ }
Expand description

ComponentCompiler is the entry point to the Slint interpreter that can be used to load .slint files or compile them on-the-fly from a string.

Implementations§

Returns a new ComponentCompiler.

Sets the include paths used for looking up .slint imports to the specified vector of paths.

Returns the include paths the component compiler is currently configured with.

Sets the style to be used for widgets.

Use the “material” style as widget style when compiling:

use slint_interpreter::{ComponentDefinition, ComponentCompiler, ComponentHandle};

let mut compiler = ComponentCompiler::default();
compiler.set_style("material".into());
let definition =
    spin_on::spin_on(compiler.build_from_path("hello.slint"));

Returns the widget style the compiler is currently using when compiling .slint files.

Sets the callback that will be invoked when loading imported .slint files. The specified file_loader_callback parameter will be called with a canonical file path as argument and is expected to return a future that, when resolved, provides the source code of the .slint file to be imported as a string. If an error is returned, then the build will abort with that error. If None is returned, it means the normal resolution algorithm will proceed as if the hook was not in place (i.e: load from the file system following the include paths)

Returns the diagnostics that were produced in the last call to Self::build_from_path or Self::build_from_source.

Compile a .slint file into a ComponentDefinition

Returns the compiled ComponentDefinition if there were no errors.

Any diagnostics produced during the compilation, such as warnings or errors, are collected in this ComponentCompiler and can be retrieved after the call using the Self::diagnostics() function. The print_diagnostics function can be used to display the diagnostics to the users.

Diagnostics from previous calls are cleared when calling this function.

If the path is "-", the file will be read from stdin.

This function is async but in practice, this is only asynchronous if Self::set_file_loader was called and its future is actually asynchronous. If that is not used, then it is fine to use a very simple executor, such as the one provided by the spin_on crate

Compile some .slint code into a ComponentDefinition

The path argument will be used for diagnostics and to compute relative paths while importing.

Any diagnostics produced during the compilation, such as warnings or errors, are collected in this ComponentCompiler and can be retrieved after the call using the Self::diagnostics() function. The print_diagnostics function can be used to display the diagnostics to the users.

Diagnostics from previous calls are cleared when calling this function.

This function is async but in practice, this is only asynchronous if Self::set_file_loader is set and its future is actually asynchronous. If that is not used, then it is fine to use a very simple executor, such as the one provided by the spin_on crate

Trait Implementations§

Returns the “default value” for a type. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The none-equivalent value.
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Should always be Self
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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more