Struct dioxus_rsx::CallBody

source ·
pub struct CallBody {
    pub roots: Vec<BodyNode>,
}
Expand description

The Callbody is the contents of the rsx! macro

It is a list of BodyNodes, which are the different parts of the template. The Callbody contains no information about how the template will be rendered, only information about the parsed tokens.

Every callbody should be valid, so you can use it to build a template. To generate the code used to render the template, use the ToTokens impl on the Callbody, or with the render_with_location method.

Fields§

§roots: Vec<BodyNode>

Implementations§

source§

impl CallBody

source

pub fn render_with_location(&self, location: String) -> TokenStream2

Render the template with a manually set file location. This should be used when multiple rsx! calls are used in the same macro

source

pub fn update_template<Ctx: HotReloadingContext>( &self, old: Option<CallBody>, location: &'static str ) -> Option<Template>

This will try to create a new template from the current body and the previous body. This will return None if the rsx has some dynamic part that has changed.

The previous_location is the location of the previous template at the time the template was originally compiled. It’s up to you the implementor to trace the template location back to the original source code. Generally you can simply just match the location from the syn::File type to the template map living in the renderer.

When you implement hotreloading, you’re likely just going to parse the source code into the Syn::File type, which should make retrieving the template location easy.

§Note:
  • This function intentionally leaks memory to create a static template.
  • Keeping the template static allows us to simplify the core of dioxus and leaking memory in dev mode is less of an issue.
§Longer note about sub templates:

Sub templates when expanded in rustc use the same file/lin/col information as the parent template. This can be annoying when you’re trying to get a location for a sub template and it’s pretending that it’s its parent. The new implementation of this aggregates all subtemplates into the TemplateRenderer and then assigns them unique IDs based on the byte index of the template, working around this issue.

§TODO:

A longer term goal would be to provide some sort of diagnostics to the user as to why the template was not updated, giving them an option to revert to the previous template as to not require a full rebuild.

Trait Implementations§

source§

impl Debug for CallBody

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CallBody

source§

fn default() -> CallBody

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

impl Parse for CallBody

source§

fn parse(input: ParseStream<'_>) -> Result<Self>

source§

impl ToTokens for CallBody

source§

fn to_tokens(&self, out_tokens: &mut TokenStream2)

Write self to the given TokenStream. Read more
source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. 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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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> Spanned for T
where T: Spanned + ?Sized,

source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

source§

fn super_from(input: T) -> O

Convert from a type to another type.
source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

source§

fn super_into(self) -> O

Convert from a type to another type.
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.
source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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