Skip to content

Commit ef9237b

Browse files
committed
docs: simplify a bit example expansion
remove recursive macro expansions basically
1 parent 3d3bc8b commit ef9237b

File tree

1 file changed

+9
-48
lines changed

1 file changed

+9
-48
lines changed

README.md

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ fn connect(config: Config) -> Result<Client, ConnectionError> {
7171

7272
generates a matching expanded function invoking it:
7373

74-
<details><summary>Show macro expansion</summary>
75-
7674
```rust
77-
#[doc = " Connect using the given credentials to the default server, and return a [Client] to interact with it."]
7875
fn connect(config: Config) -> Result<Client, ConnectionError> {
7976
super::tokio().block_on(Client::connect(config))
8077
}
78+
8179
#[no_mangle]
8280
#[allow(unused_unit)]
8381
pub extern "system" fn Java_mp_code_Client_connect<'local>(
@@ -89,13 +87,7 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
8987
let config_new = match jni_toolbox::from_java_static::<Config>(&mut env, config) {
9088
Ok(x) => x,
9189
Err(e) => {
92-
let _ = env.throw_new(
93-
"java/lang/RuntimeException",
94-
$crate::__export::must_use({
95-
let res = $crate::fmt::format($crate::__export::format_args!("{e:?}"));
96-
res
97-
}),
98-
);
90+
let _ = env.throw_new("java/lang/RuntimeException", format!("{e:?}"));
9991
return std::ptr::null_mut();
10092
}
10193
};
@@ -104,36 +96,13 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
10496
let ret = match result {
10597
Ok(x) => x,
10698
Err(e) => match env_copy.find_class(e.jclass()) {
107-
Err(e) => {
108-
$crate::panicking::panic_fmt($crate::const_format_args!(
109-
"error throwing Java exception -- failed resolving error class: {e}"
110-
));
111-
}
112-
Ok(class) => match env_copy.new_string($crate::__export::must_use({
113-
let res = $crate::fmt::format($crate::__export::format_args!("{e:?}"));
114-
res
115-
})) {
116-
Err(e) => {
117-
$crate::panicking::panic_fmt($crate::const_format_args!(
118-
"error throwing Java exception -- failed creating error string: {e}"
119-
));
120-
}
121-
Ok(msg) => match env_copy.new_object(
122-
class,
123-
"(Ljava/lang/String;)V",
124-
&[jni::objects::JValueGen::Object(&msg)],
125-
) {
126-
Err(e) => {
127-
$crate::panicking::panic_fmt($crate::const_format_args!(
128-
"error throwing Java exception -- failed creating object: {e}"
129-
));
130-
}
99+
Err(e) => panic!("error throwing Java exception -- failed resolving error class: {e}"),
100+
Ok(class) => match env_copy.new_string(format!("{e:?}")) {
101+
Err(e) => panic!("error throwing Java exception -- failed creating error string: {e}"),
102+
Ok(msg) => match env_copy.new_object(class, "(Ljava/lang/String;)V", &[jni::objects::JValueGen::Object(&msg)]) {
103+
Err(e) => panic!("error throwing Java exception -- failed creating object: {e}"));
131104
Ok(obj) => match env_copy.throw(jni::objects::JThrowable::from(obj)) {
132-
Err(e) => {
133-
$crate::panicking::panic_fmt($crate::const_format_args!(
134-
"error throwing Java exception -- failed throwing: {e}"
135-
));
136-
}
105+
Err(e) => panic!("error throwing Java exception -- failed throwing: {e}"),
137106
Ok(_) => return std::ptr::null_mut(),
138107
},
139108
},
@@ -143,20 +112,12 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
143112
match ret.into_java(&mut env_copy) {
144113
Ok(fin) => fin,
145114
Err(e) => {
146-
let _ = env_copy.throw_new(
147-
"java/lang/RuntimeException",
148-
$crate::__export::must_use({
149-
let res = $crate::fmt::format($crate::__export::format_args!("{e:?}"));
150-
res
151-
}),
152-
);
115+
let _ = env_copy.throw_new("java/lang/RuntimeException", format!("{e:?}"));
153116
std::ptr::null_mut()
154117
}
155118
}
156119
}
157120
```
158-
</details>
159-
160121

161122
## Status
162123
This crate is early and intended mostly to maintain [`codemp`](https://github.com/hexedtech/codemp)'s Java bindings, so things not used

0 commit comments

Comments
 (0)