jvm-bytecode 0.5.0

JVM class and bytecode support for the jvm crate
Documentation
use alloc::{
    borrow::Cow,
    boxed::Box,
    string::{String, ToString},
    sync::Arc,
};
use core::fmt::{self, Debug, Formatter};

use jvm::{ArrayClassDefinition, ClassInstance, Jvm, Result};

use crate::array_class_instance::ArrayClassInstanceImpl;

struct ArrayClassDefinitionInner {
    element_type_name: String,
}

#[derive(Clone)]
pub struct ArrayClassDefinitionImpl {
    inner: Arc<ArrayClassDefinitionInner>,
}

impl ArrayClassDefinitionImpl {
    pub fn new(element_type_name: &str) -> Self {
        Self {
            inner: Arc::new(ArrayClassDefinitionInner {
                element_type_name: element_type_name.to_string(),
            }),
        }
    }
}

#[async_trait::async_trait]
impl ArrayClassDefinition for ArrayClassDefinitionImpl {
    fn element_type_name(&self) -> Cow<'_, str> {
        (&self.inner.element_type_name).into()
    }

    async fn instantiate_array(&self, _: &Jvm, length: usize) -> Result<Box<dyn ClassInstance>> {
        Ok(Box::new(ArrayClassInstanceImpl::new(self, length)))
    }
}

impl Debug for ArrayClassDefinitionImpl {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "ArrayClass({})", self.inner.element_type_name)
    }
}