pub struct Cache { /* private fields */ }Expand description
A cache of diagnostic sources.
Cache manages multiple source files and their associated data,
allowing for efficient multi-source diagnostics. It can be reused
across multiple render operations.
§Source Lifetime Management
The cache automatically handles different source types:
- Borrowed sources (
&str): Content must remain valid until rendering completes - Owned sources (
String,Vec<u8>, etc.): Content is stored in the cache’s internal memory managed by the C library
§Single Source Convenience
For simple single-source diagnostics, you can pass sources directly to
rendering methods without creating an explicit Cache. See Report::render_to_string()
for examples.
§Example
use musubi::{Cache, Report, Level};
let cache = Cache::new()
.with_source(("let x = 42;", "main.rs")) // Source 0
.with_source(("fn foo() {}", "lib.rs")); // Source 1
let mut report = Report::new()
.with_title(Level::Error, "Multiple files")
.with_label((0..3, 0)) // Label in main.rs
.with_message("here")
.with_label((3..6, 1)) // Label in lib.rs
.with_message("and here");
report.render_to_stdout(&cache)?;Implementations§
Source§impl Cache
impl Cache
Sourcepub fn with_source<S: AddToCache>(self, content: S) -> Self
pub fn with_source<S: AddToCache>(self, content: S) -> Self
Add a source to the cache.
Accepts both borrowed (&str) and owned (String) content.
For other byte buffers like Vec<u8>, use OwnedSource.
Borrowed content must remain valid until rendering completes.
Owned content is stored in the cache’s internal memory.
§Example
let cache = Cache::new()
.with_source("let x = 42;") // &str - borrowed
.with_source(("fn main() {}".to_string(), "main.rs")) // String - owned
.with_source((OwnedSource::new(vec![b'a', b'b', b'c']), "data.bin")); // Vec<u8>Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl !Send for Cache
impl !Sync for Cache
impl Unpin for Cache
impl UnwindSafe for Cache
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