pub trait World {
// Required methods
fn entry_point(&self) -> FileId;
fn source(&self, file_id: FileId) -> Result<Source, FileError>;
fn library(&self) -> &Library;
fn write(
&self,
f: &mut dyn FnMut(&mut dyn Write) -> Result<(), Error>,
) -> Result<(), Error>;
fn read(
&self,
f: &mut dyn FnMut(&mut dyn Read) -> Result<(), Error>,
) -> Result<(), Error>;
// Provided methods
fn with_io(
&self,
f: &mut dyn FnMut(&mut dyn Read, &mut dyn Write) -> Result<(), Error>,
) -> Result<(), Error> { ... }
fn name(&self, id: FileId) -> String { ... }
fn related_source(&self, span: Span) -> Option<Source> { ... }
}Expand description
Defines how Compose interacts with the outside world.
World is an abstraction layer between the Compose runtime and its external environment.
It is responsible for:
- Loading source files and defining the program entrypoint.
- Providing access to a standard library.
- Provide I/O primitives for stdout.
This trait allows Compose to be embedded in different environments (e.g. CLI tools, editors, tests, or sandboxes) without hard-coding filesystem or I/O behaviour.
Required Methods§
Sourcefn entry_point(&self) -> FileId
fn entry_point(&self) -> FileId
Returns the FileId of the entrypoint of the program.
Sourcefn library(&self) -> &Library
fn library(&self) -> &Library
Returns a reference to the standard library available to the program.
Provided Methods§
Sourcefn with_io(
&self,
f: &mut dyn FnMut(&mut dyn Read, &mut dyn Write) -> Result<(), Error>,
) -> Result<(), Error>
fn with_io( &self, f: &mut dyn FnMut(&mut dyn Read, &mut dyn Write) -> Result<(), Error>, ) -> Result<(), Error>
Provides read and write access to the programs input and output stream.
The provided closure is given exclusive access to the reader and writer for the duration of the call.
Sourcefn name(&self, id: FileId) -> String
fn name(&self, id: FileId) -> String
Returns a human-readable name for the given file identifier.
By default, this is derived from the file’s path.
Attempts to retrieve the source associated with the given span.
This is primarily used for diagnostics and error reporting.
Trait Implementations§
Source§impl<'a> Files<'a> for &dyn World
impl<'a> Files<'a> for &dyn World
Source§type FileId = FileId
type FileId = FileId
diagnostic::Labels in the corresponding source files.