risingwave_jni_core

Macro cast_jvalue

source
macro_rules! cast_jvalue {
    ({ boolean }, $value:expr) => { ... };
    ({ byte }, $value:expr) => { ... };
    ({ char }, $value:expr) => { ... };
    ({ double }, $value:expr) => { ... };
    ({ float }, $value:expr) => { ... };
    ({ int }, $value:expr) => { ... };
    ({ long }, $value:expr) => { ... };
    ({ short }, $value:expr) => { ... };
    ({ void }, $value:expr) => { ... };
    ({ byte[] }, $value:expr) => { ... };
    ({ $($class:tt)+ }, $value:expr) => { ... };
}
Expand description

Cast a JValueGen to a concrete type by the given type

use jni::objects::JValue;
use jni::sys::JNI_TRUE;
use risingwave_jni_core::cast_jvalue;
assert_eq!(cast_jvalue!({boolean}, JValue::Bool(JNI_TRUE)), true);
assert_eq!(cast_jvalue!({byte}, JValue::Byte(10 as i8)), 10);
assert_eq!(cast_jvalue!({char}, JValue::Char('c' as u16)), 'c' as u16);
assert_eq!(cast_jvalue!({double}, JValue::Double(3.14)), 3.14);
assert_eq!(cast_jvalue!({float}, JValue::Float(3.14)), 3.14);
assert_eq!(cast_jvalue!({int}, JValue::Int(10)), 10);
assert_eq!(cast_jvalue!({long}, JValue::Long(10)), 10);
assert_eq!(cast_jvalue!({short}, JValue::Short(10)), 10);
cast_jvalue!({void}, JValue::Void);
let null = jni::objects::JObject::null();
let _: &jni::objects::JObject<'_> = cast_jvalue!({String}, JValue::Object(&null));
let _: jni::objects::JByteArray<'_> = cast_jvalue!({byte[]}, jni::objects::JValueOwned::Object(null));