You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: fenum.rs
    path of file: ./repos/flapigen-rs/macroslib/src/java_jni
    
    the code of the file until where you have to start completion: use log::trace;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use std::{io::Write, rc::Rc};
use syn::{Ident, Type};

use super::{
    java_class_full_name, java_class_name_to_jni, java_code::doc_comments_to_java_comments,
    map_write_err, JavaContext,
};
use crate::{
    error::{invalid_src_id_span, DiagnosticError, Result},
    file_cache::FileWriteCache,
    typemap::{
        ast::{parse_ty_with_given_span, ForeignTypeName},
        ty::{ForeignConversionIntermediate, ForeignConversionRule, ForeignTypeS},
        RustTypeIdx, TypeConvCode, TypeConvEdge, FROM_VAR_TEMPLATE, TO_VAR_TEMPLATE,
    },
    types::ForeignEnumInfo,
    WRITE_TO_MEM_FAILED_MSG,
};

const C_LIKE_ENUM_TRAIT: &str = "SwigForeignCLikeEnum";

pub(in crate::java_jni) fn generate_enum(
    ctx: &mut JavaContext,
    fenum: &ForeignEnumInfo,
) -> Result<()> {
    let enum_name = &fenum.name;
    trace!("generate_enum: enum {}", enum_name);
    if (fenum.items.len() as u64) >= (i32::max_value() as u64) {
        return Err(DiagnosticError::new(
            fenum.src_id,
            fenum.span(),
            "Too many items in
    
fn generate_rust_code_for_enum(ctx: &mut JavaContext, fenum: &ForeignEnumInfo) -> Result<()> {
    let mut arms_to_jint = Vec::with_capacity(fenum.items.len());
    let mut arms_from_jint = Vec::with_capacity(fenum.items.len());
    assert!((fenum.items.len() as u64) <= u64::from(i32::max_value() as u32));
    for (i, item) in fenum.items.iter().enumerate() {
        let item_name = &item.rust_name;
        let idx = i as i32;
        arms_to_jint.push(quote! { #item_name => #idx });
        arms_from_jint.push(quote! { #idx => #item_name });
    }

    let rust_enum_name = &fenum.name;
    let trait_name = syn::Ident::new(C_LIKE_ENUM_TRAIT, Span::call_site());

    ctx.rust_code.push(quote! {
        impl #trait_name for #rust_enum_name {
            fn as_jint(&self) -> jint {
                match *self {
                    #(#arms_to_jint),*
                }
            }
            fn from_jint(x: jint) -> Self {
                match x {
                    #(#arms_from_jint),*
                    ,
                    _ => panic!(concat!("{} not expected for ", stringify!(#rust_enum_name)), x),
                }
            }
        }
    });

    Ok(())
}