• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use jni::{
16     objects::{JObject, JThrowable},
17     JNIEnv,
18 };
19 use pourover::desc::ClassDesc;
20 
21 static INVALID_HANDLE_EXCEPTION_CLASS: ClassDesc =
22     ClassDesc::new("com/google/android/nearby/presence/rust/Handle$InvalidHandleException");
23 
24 /// Rust representation of `class InvalidHandleException`.
25 #[repr(transparent)]
26 pub struct InvalidHandleException<Obj>(pub Obj);
27 
28 impl<'local> InvalidHandleException<JObject<'local>> {
29     /// Create a new instance.
construct(env: &mut JNIEnv<'local>) -> jni::errors::Result<Self>30     pub fn construct(env: &mut JNIEnv<'local>) -> jni::errors::Result<Self> {
31         pourover::call_constructor!(env, &INVALID_HANDLE_EXCEPTION_CLASS, "()V").map(Self)
32     }
33 
34     /// Create a new instance and throw it.
throw_new(env: &mut JNIEnv<'local>) -> jni::errors::Result<()>35     pub fn throw_new(env: &mut JNIEnv<'local>) -> jni::errors::Result<()> {
36         Self::construct(env)?.throw(env)
37     }
38 }
39 
40 impl<'local, Obj: AsRef<JObject<'local>>> InvalidHandleException<Obj> {
41     /// Throw this exception.
throw<'env>(&self, env: &mut JNIEnv<'env>) -> jni::errors::Result<()>42     pub fn throw<'env>(&self, env: &mut JNIEnv<'env>) -> jni::errors::Result<()> {
43         env.throw(<&JThrowable>::from(self.0.as_ref()))
44     }
45 }
46