Struct slint_interpreter::ComponentCompiler

source ·
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§

source§

impl ComponentCompiler

source

pub fn new() -> Self

Returns a new ComponentCompiler.

source

pub fn set_include_paths(&mut self, include_paths: Vec<PathBuf>)

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

source

pub fn include_paths(&self) -> &Vec<PathBuf>

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

source

pub fn set_library_paths(&mut self, library_paths: HashMap<String, PathBuf>)

Sets the library paths used for looking up @library imports to the specified map of library names to paths.

source

pub fn library_paths(&self) -> &HashMap<String, PathBuf>

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

source

pub fn set_style(&mut self, style: String)

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"));
source

pub fn style(&self) -> Option<&String>

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

source

pub fn set_translation_domain(&mut self, domain: String)

The domain used for translations

source

pub fn set_file_loader( &mut self, file_loader_fallback: impl Fn(&Path) -> Pin<Box<dyn Future<Output = Option<Result<String>>>>> + 'static )

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)

source

pub fn diagnostics(&self) -> &Vec<Diagnostic>

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

source

pub async fn build_from_path<P: AsRef<Path>>( &mut self, path: P ) -> Option<ComponentDefinition>

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. If the extension of the file .rs, the first slint! macro from a rust file will be extracted

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

source

pub async fn build_from_source( &mut self, source_code: String, path: PathBuf ) -> Option<ComponentDefinition>

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§

source§

impl Default for ComponentCompiler

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more