Skip to content

Commit

Permalink
rune: Improve unit and prepare documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 27, 2024
1 parent 260a675 commit dfb60ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/rune-shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod support {
pub use anyhow::Result;
}

#[cfg(feature = "rune-core")]
pub mod runtime {
use rune_core::hash::Hash;

Expand Down
27 changes: 23 additions & 4 deletions crates/rune/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,21 @@ impl core::error::Error for BuildError {
}
}

/// Entry point to building [Sources] of Rune using the default unit storage.
/// Entry point to building a collection [`Sources`] of Rune into a default
/// executable [`Unit`].
///
/// Uses the [Source::name](crate::Source::name) when generating diagnostics to
/// reference the file.
/// This returns a [`Build`] instance using a default configuration for a build
/// that can be customized.
///
/// By default, if any error is encountered during compilation the error type
/// [`BuildError`] doesn't provide any diagnostics on what went wrong. To get
/// rich diagnostics you should instead associated a [`Diagnostics`] type
/// through [`Build::with_diagnostics`] and examine it before handling any
/// [`Err(BuildError)`] produced.
///
/// Uses the [Source::name] when generating diagnostics to reference the file.
///
/// [Source::name]: crate::Source::name
///
/// # Examples
///
Expand Down Expand Up @@ -133,7 +144,11 @@ where
}
}

/// High level helper for setting up a build of Rune sources into a [Unit].
/// A builder for a [Unit].
///
/// See [`rune::prepare`] for more.
///
/// [`rune::prepare`]: prepare
pub struct Build<'a, S> {
sources: &'a mut Sources,
context: Option<&'a Context>,
Expand Down Expand Up @@ -270,6 +285,10 @@ impl<'a, S> Build<'a, S> {
}

/// Build a [`Unit`] with the current configuration.
///
/// See [`rune::prepare`] for more.
///
/// [`rune::prepare`]: prepare
pub fn build(mut self) -> Result<Unit<S>, BuildError>
where
S: Default + UnitEncoder,
Expand Down
4 changes: 3 additions & 1 deletion crates/rune/src/runtime/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub type DefaultStorage = ArrayUnit;
#[cfg(rune_byte_code)]
pub type DefaultStorage = ByteCodeUnit;

/// Instructions and debug info from a single source file.
/// Instructions and debug info from a single compilation.
///
/// See [`rune::prepare`] for more.
#[derive(Debug, TryClone, Default, Serialize, Deserialize)]
#[serde(bound = "S: Serialize + DeserializeOwned")]
#[try_clone(bound = {S: TryClone})]
Expand Down

0 comments on commit dfb60ca

Please sign in to comment.