Skip to content

Commit d04930c

Browse files
committed
Run rustfmt
1 parent 29fabdd commit d04930c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

examples/webxr/src/lib.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#[macro_use] mod utils;
1+
#[macro_use]
2+
mod utils;
23

34
use futures::{future, Future};
45
use js_sys::Promise;
6+
use std::cell::RefCell;
7+
use std::collections::HashMap;
8+
use std::rc::Rc;
9+
use utils::set_panic_hook;
510
use wasm_bindgen::prelude::*;
611
use wasm_bindgen::prelude::*;
712
use wasm_bindgen::JsCast;
813
use wasm_bindgen_futures::future_to_promise;
914
use wasm_bindgen_futures::JsFuture;
1015
use web_sys::*;
11-
use std::cell::RefCell;
12-
use std::collections::HashMap;
13-
use std::rc::Rc;
14-
use utils::set_panic_hook;
15-
1616

1717
// A macro to provide `println!(..)`-style syntax for `console.log` logging.
1818
macro_rules! log {
@@ -21,54 +21,50 @@ macro_rules! log {
2121
}
2222
}
2323

24-
2524
fn request_animation_frame(session: &XrSession, f: &Closure<dyn FnMut(f64, XrFrame)>) -> i32 {
2625
// This turns the Closure into a js_sys::Function
2726
// See https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/closure/struct.Closure.html#casting-a-closure-to-a-js_sysfunction
28-
session
29-
.request_animation_frame(f.as_ref().unchecked_ref())
27+
session.request_animation_frame(f.as_ref().unchecked_ref())
3028
}
3129

32-
3330
pub fn create_webgl_context(xr_mode: bool) -> Result<WebGl2RenderingContext, JsValue> {
3431
let canvas = web_sys::window()
35-
.unwrap()
36-
.document()
37-
.unwrap()
38-
.get_element_by_id("canvas")
39-
.unwrap()
40-
.dyn_into::<HtmlCanvasElement>()
41-
.unwrap();
32+
.unwrap()
33+
.document()
34+
.unwrap()
35+
.get_element_by_id("canvas")
36+
.unwrap()
37+
.dyn_into::<HtmlCanvasElement>()
38+
.unwrap();
4239

4340
let gl: WebGl2RenderingContext = if xr_mode {
4441
let mut gl_attribs = HashMap::new();
4542
gl_attribs.insert(String::from("xrCompatible"), true);
4643
let js_gl_attribs = JsValue::from_serde(&gl_attribs).unwrap();
4744

48-
canvas.get_context_with_context_options("webgl2", &js_gl_attribs)?.unwrap().dyn_into()?
49-
}
50-
else {
45+
canvas
46+
.get_context_with_context_options("webgl2", &js_gl_attribs)?
47+
.unwrap()
48+
.dyn_into()?
49+
} else {
5150
canvas.get_context("webgl2")?.unwrap().dyn_into()?
5251
};
5352

5453
Ok(gl)
5554
}
5655

57-
5856
#[wasm_bindgen]
5957
pub struct XrApp {
6058
session: Rc<RefCell<Option<XrSession>>>,
61-
gl: Rc<WebGl2RenderingContext>
59+
gl: Rc<WebGl2RenderingContext>,
6260
}
6361

64-
6562
#[wasm_bindgen]
6663
impl XrApp {
67-
6864
#[wasm_bindgen(constructor)]
6965
pub fn new() -> XrApp {
7066
set_panic_hook();
71-
67+
7268
let session = Rc::new(RefCell::new(None));
7369

7470
let xr_mode = true;
@@ -83,7 +79,7 @@ impl XrApp {
8379
let gpu = navigator.gpu();
8480
let xr = navigator.xr();
8581
let session_mode = XrSessionMode::Inline;
86-
let session_supported_promise = xr.is_session_supported(session_mode);
82+
let session_supported_promise = xr.is_session_supported(session_mode);
8783

8884
// Note: &self is on the stack so we can't use it in a future (which will
8985
// run after the &self reference is out or scope). Clone ref to the parts
@@ -93,17 +89,18 @@ impl XrApp {
9389
let gl = self.gl.clone();
9490

9591
let future_ = async move {
96-
let supports_session = wasm_bindgen_futures::JsFuture::from(session_supported_promise).await;
92+
let supports_session =
93+
wasm_bindgen_futures::JsFuture::from(session_supported_promise).await;
9794
let supports_session = supports_session.unwrap();
9895
if supports_session == false {
9996
log!("XR session not supported");
10097
return Ok(JsValue::from("XR session not supported"));
10198
}
102-
99+
103100
let xr_session_promise = xr.request_session(session_mode);
104101
let xr_session = wasm_bindgen_futures::JsFuture::from(xr_session_promise).await;
105102
let xr_session: XrSession = xr_session.unwrap().into();
106-
103+
107104
let xr_gl_layer = XrWebGlLayer::new_with_web_gl2_rendering_context(&xr_session, &gl)?;
108105
let mut render_state_init = XrRenderStateInit::new();
109106
render_state_init.base_layer(Some(&xr_gl_layer));
@@ -140,11 +137,14 @@ impl XrApp {
140137
// Schedule ourself for another requestAnimationFrame callback.
141138
// TODO: WebXR Samples call this at top of request_animation_frame - should this be moved?
142139
request_animation_frame(&sess, f.borrow().as_ref().unwrap());
143-
144140
}) as Box<dyn FnMut(f64, XrFrame)>));
145141

146142
let session: &Option<XrSession> = &self.session.borrow();
147-
let sess: &XrSession = if let Some(sess) = session { sess } else { return () };
143+
let sess: &XrSession = if let Some(sess) = session {
144+
sess
145+
} else {
146+
return ();
147+
};
148148

149149
request_animation_frame(sess, g.borrow().as_ref().unwrap());
150150
}

0 commit comments

Comments
 (0)