pub struct Compiler { /* private fields */ }Expand description
This is the entry point of the crate, it can be used to load a .slint file and
compile it into a CompilationResult.
Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn set_include_paths(&mut self, include_paths: Vec<PathBuf>)
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.
Sourcepub fn include_paths(&self) -> &Vec<PathBuf>
pub fn include_paths(&self) -> &Vec<PathBuf>
Returns the include paths the component compiler is currently configured with.
Sourcepub fn set_library_paths(&mut self, library_paths: HashMap<String, PathBuf>)
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.
Sourcepub fn library_paths(&self) -> &HashMap<String, PathBuf>
pub fn library_paths(&self) -> &HashMap<String, PathBuf>
Returns the library paths the component compiler is currently configured with.
Sourcepub fn set_style(&mut self, style: String)
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, Compiler, ComponentHandle};
let mut compiler = Compiler::default();
compiler.set_style("material".into());
let result = spin_on::spin_on(compiler.build_from_path("hello.slint"));Sourcepub fn style(&self) -> Option<&String>
pub fn style(&self) -> Option<&String>
Returns the widget style the compiler is currently using when compiling .slint files.
Sourcepub fn set_translation_domain(&mut self, domain: String)
pub fn set_translation_domain(&mut self, domain: String)
The domain used for translations
Sourcepub fn set_file_loader(
&mut self,
file_loader_fallback: impl Fn(&Path) -> Pin<Box<dyn Future<Output = Option<Result<String>>>>> + 'static,
)
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)
Sourcepub async fn build_from_path<P: AsRef<Path>>(
&self,
path: P,
) -> CompilationResult
pub async fn build_from_path<P: AsRef<Path>>( &self, path: P, ) -> CompilationResult
Compile a .slint file
Returns a structure that holds the diagnostics and the compiled components.
Any diagnostics produced during the compilation, such as warnings or errors, can be retrieved
after the call using CompilationResult::diagnostics().
If the file was compiled without error, the list of component names can be obtained with
CompilationResult::component_names, and the compiled components themselves with
CompilationResult::component().
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
Sourcepub async fn build_from_source(
&self,
source_code: String,
path: PathBuf,
) -> CompilationResult
pub async fn build_from_source( &self, source_code: String, path: PathBuf, ) -> CompilationResult
Compile some .slint code
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, can be retrieved
after the call using CompilationResult::diagnostics().
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§
Auto Trait Implementations§
impl Freeze for Compiler
impl !RefUnwindSafe for Compiler
impl !Send for Compiler
impl !Sync for Compiler
impl Unpin for Compiler
impl !UnwindSafe for Compiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.