diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2015-09-25 16:29:23 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2015-09-25 16:34:08 +0200 |
commit | d12dbf94f2a55174b7cdaa5bd539d90b83813145 (patch) | |
tree | 43b5005c53eeb233a961d9ccfb8a1ae3ba4d1c8c | |
parent | 5d7d745ab4b6a0a6bdc124c2d50a5667f9f47b7e (diff) | |
download | servo-d12dbf94f2a55174b7cdaa5bd539d90b83813145.tar.gz servo-d12dbf94f2a55174b7cdaa5bd539d90b83813145.zip |
Refactor `if let Some(a) { Some(b) } else { None }`
Prefer `Option::map` instead.
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 8cd254b4fe8..73be8d760ee 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -114,27 +114,23 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { #[allow(unsafe_code)] unsafe fn get_renderer_id(&self) -> Option<usize> { let ref canvas = *self.unsafe_get(); - if let Some(context) = canvas.context.get() { + canvas.context.get().map(|context| { match context { - CanvasContext::Context2d(context) => Some(context.to_layout().get_renderer_id()), - CanvasContext::WebGL(context) => Some(context.to_layout().get_renderer_id()), + CanvasContext::Context2d(context) => context.to_layout().get_renderer_id(), + CanvasContext::WebGL(context) => context.to_layout().get_renderer_id(), } - } else { - None - } + }) } #[allow(unsafe_code)] unsafe fn get_ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> { let ref canvas = *self.unsafe_get(); - if let Some(context) = canvas.context.get() { + canvas.context.get().map(|context| { match context { - CanvasContext::Context2d(context) => Some(context.to_layout().get_ipc_renderer()), - CanvasContext::WebGL(context) => Some(context.to_layout().get_ipc_renderer()), + CanvasContext::Context2d(context) => context.to_layout().get_ipc_renderer(), + CanvasContext::WebGL(context) => context.to_layout().get_ipc_renderer(), } - } else { - None - } + }) } #[allow(unsafe_code)] @@ -151,14 +147,12 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { impl HTMLCanvasElement { pub fn ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> { - if let Some(context) = self.context.get() { + self.context.get().map(|context| { match context { - CanvasContext::Context2d(context) => Some(context.root().r().ipc_renderer()), - CanvasContext::WebGL(context) => Some(context.root().r().ipc_renderer()), + CanvasContext::Context2d(context) => context.root().r().ipc_renderer(), + CanvasContext::WebGL(context) => context.root().r().ipc_renderer(), } - } else { - None - } + }) } pub fn get_or_init_2d_context(&self) -> Option<Root<CanvasRenderingContext2D>> { |