To build the slicec library you need to have Rust and Cargo installed. The recommended method to install Rust is by using rustup.
The slicec library is a Rust library that can be used to compile Slice definitions into a CompilationState
struct.
The CompilationState
struct contains the AST and any diagnostics that were emitted during compilation.
The simplest way to compile a Slice definition is by using the compile_from_strings
function:
pub fn main() {
let slice = "
module GreeterExample
/// Represents a simple greeter.
interface Greeter {
/// Creates a personalized greeting.
/// @param name: The name of the person to greet.
/// @returns: The greeting.
greet(name: string) -> string
}
";
let compilation_state = slice::compile_from_strings(&[slice], None);
}
This function takes an array of strings containing Slice definitions and an optional set of compilation options.
Alternatively, you can create SliceOptions
and use the compile_from_options
function to create a command line
application that compiles Slice definitions:
// main.rs
pub fn main() {
let options = SliceOptions::parse();
let slice_options = &options.slice_options;
let compilation_state = slice::compile_from_options(slice_options);
}
// greeter.slice
module GreeterExample
/// Represents a simple greeter.
interface Greeter {
/// Creates a personalized greeting.
/// @param name: The name of the person to greet.
/// @returns: The greeting.
greet(name: string) -> string
}
Build and run using Cargo:
cargo build
cargo run greeter.slice
The test suite can be run from the command line by running cargo test
in the repository.
Code coverage reports can be generated using cargo-llvm-cov from a regular command prompt, using the following command
For Linux and macOS:
cargo install cargo-llvm-cov
cargo llvm-cov --html
The output html is in the target/llvm-cov/html/
directory.