/ristretto

Crates for the JVM Specification

Primary LanguageRustApache License 2.0Apache-2.0

Ristretto

ci Documentation Code Coverage Benchmarks Latest version License Semantic Versioning

Crates for the JVM Specification

Getting Started

Crates for the JVM Specification

Features

  • loading classes from any version of AWS Corretto
  • load classes from directories, jars, modules
  • url classes loading from jars and modules
  • reading, writing, verifying classes for any version of Java version up to 24
  • verification of class files is supported, but is still a work in progress.

Examples

Load a class from the Java runtime

use ristretto_classloader::{runtime, ClassLoader, Result};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<()> {
    let (version, class_loader) = runtime::class_loader("21").await?;
    let class_name = "java.util.HashMap";
    println!("Loading {class_name} from Java runtime {version}");
    let class = ClassLoader::load_class(&Arc::new(class_loader), class_name).await?;
    println!("{class:?}");
    Ok(())
}

Create a class file

use ristretto_classfile::{ClassFile, ConstantPool, Result, Version};

fn main() -> Result<()> {
    let mut constant_pool = ConstantPool::default();
    let this_class = constant_pool.add_class("Foo")?;
    let class_file = ClassFile {
        version: Version::Java21 { minor: 0 },
        constant_pool,
        this_class,
        ..Default::default()
    };
    class_file.verify()
}

Safety

These crates use #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

VSCode Development Container
GitHub Codespaces