mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add a helper for ignoring the EOF condition so we don't crash
This commit is contained in:
parent
e2b7885b73
commit
4d23ce41af
2 changed files with 15 additions and 0 deletions
14
src/components/util/io.rs
Normal file
14
src/components/util/io.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::rt::io::{io_error, EndOfFile};
|
||||
|
||||
/// Ignore the end-of-file condition within a block of code.
|
||||
pub fn ignoring_eof<U>(cb: &fn() -> U) -> U {
|
||||
io_error::cond.trap(|e|
|
||||
match e.kind {
|
||||
EndOfFile => (),
|
||||
_ => io_error::cond.raise(e)
|
||||
}).inside(cb)
|
||||
}
|
|
@ -22,3 +22,4 @@ pub mod tree;
|
|||
pub mod url;
|
||||
pub mod vec;
|
||||
pub mod debug;
|
||||
pub mod io;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue