pub struct HighlightedSource { /* private fields */ }Expand description
A highlighted source string with metadata and token spans.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("let x = 1;", Language::Rust, &[]);
assert_eq!(src.source(), "let x = 1;");Implementations§
Source§impl HighlightedSource
impl HighlightedSource
Sourcepub const fn from_static_parts(
source: &'static str,
language: Language,
spans: &'static [HighlightSpan],
) -> Self
pub const fn from_static_parts( source: &'static str, language: Language, spans: &'static [HighlightSpan], ) -> Self
Build highlighted source from static text and spans.
This is mainly useful for compile-time highlighters and macro output.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("let x = 1;", Language::Rust, &[]);
assert_eq!(src.language(), Language::Rust);Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
The raw source text.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("hello", Language::Rust, &[]);
assert_eq!(src.source(), "hello");Sourcepub const fn language(&self) -> Language
pub const fn language(&self) -> Language
The detected or explicitly set language, if any.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("", Language::Rust, &[]);
assert_eq!(src.language(), Language::Rust);Sourcepub fn spans(&self) -> &[HighlightSpan]
pub fn spans(&self) -> &[HighlightSpan]
The highlight spans covering the source.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("", Language::Rust, &[]);
assert!(src.spans().is_empty());Sourcepub fn segments(&self) -> Vec<HighlightSegment<'_>>
pub fn segments(&self) -> Vec<HighlightSegment<'_>>
Split the source into renderable highlighted segments.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("hello", Language::Rust, &[]);
assert_eq!(src.segments().len(), 1);Sourcepub fn lines(&self) -> Vec<Vec<HighlightSegment<'_>>>
pub fn lines(&self) -> Vec<Vec<HighlightSegment<'_>>>
Split the source into highlighted lines.
Trailing empty lines are preserved so editor renderers can keep line numbers and input rows aligned with the original source text.
use dioxus_code::Language;
use dioxus_code::advanced::HighlightedSource;
let src = HighlightedSource::from_static_parts("a\nb", Language::Rust, &[]);
assert_eq!(src.lines().len(), 2);Trait Implementations§
Source§impl Clone for HighlightedSource
impl Clone for HighlightedSource
Source§fn clone(&self) -> HighlightedSource
fn clone(&self) -> HighlightedSource
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HighlightedSource
impl Debug for HighlightedSource
Source§impl From<SourceCode> for HighlightedSource
Available on crate feature runtime only.
impl From<SourceCode> for HighlightedSource
Available on crate feature
runtime only.Source§fn from(code: SourceCode) -> Self
fn from(code: SourceCode) -> Self
Converts to this type from the input type.
Source§impl PartialEq for HighlightedSource
impl PartialEq for HighlightedSource
Source§fn eq(&self, other: &HighlightedSource) -> bool
fn eq(&self, other: &HighlightedSource) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for HighlightedSource
impl StructuralPartialEq for HighlightedSource
Auto Trait Implementations§
impl Freeze for HighlightedSource
impl RefUnwindSafe for HighlightedSource
impl Send for HighlightedSource
impl Sync for HighlightedSource
impl Unpin for HighlightedSource
impl UnsafeUnpin for HighlightedSource
impl UnwindSafe for HighlightedSource
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.