]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/mod.rs
remove implementation detail from doc
[rust.git] / src / libstd / sys / wasm / mod.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! System bindings for the wasm/web platform
12 //!
13 //! This module contains the facade (aka platform-specific) implementations of
14 //! OS level functionality for wasm. Note that this wasm is *not* the emscripten
15 //! wasm, so we have no runtime here.
16 //!
17 //! This is all super highly experimental and not actually intended for
18 //! wide/production use yet, it's still all in the experimental category. This
19 //! will likely change over time.
20 //!
21 //! Currently all functions here are basically stubs that immediately return
22 //! errors. The hope is that with a portability lint we can turn actually just
23 //! remove all this and just omit parts of the standard library if we're
24 //! compiling for wasm. That way it's a compile time error for something that's
25 //! guaranteed to be a runtime error!
26
27 use io;
28 use os::raw::c_char;
29
30 // Right now the wasm backend doesn't even have the ability to print to the
31 // console by default. Wasm can't import anything from JS! (you have to
32 // explicitly provide it).
33 //
34 // Sometimes that's a real bummer, though, so this flag can be set to `true` to
35 // enable calling various shims defined in `src/etc/wasm32-shim.js` which should
36 // help receive debug output and see what's going on. In general this flag
37 // currently controls "will we call out to our own defined shims in node.js",
38 // and this flag should always be `false` for release builds.
39 const DEBUG: bool = false;
40
41 pub mod args;
42 pub mod backtrace;
43 pub mod cmath;
44 pub mod condvar;
45 pub mod env;
46 pub mod fs;
47 pub mod memchr;
48 pub mod mutex;
49 pub mod net;
50 pub mod os;
51 pub mod os_str;
52 pub mod path;
53 pub mod pipe;
54 pub mod process;
55 pub mod rwlock;
56 pub mod stack_overflow;
57 pub mod thread;
58 pub mod thread_local;
59 pub mod time;
60 pub mod stdio;
61
62 #[cfg(not(test))]
63 pub fn init() {
64 }
65
66 pub fn unsupported<T>() -> io::Result<T> {
67     Err(unsupported_err())
68 }
69
70 pub fn unsupported_err() -> io::Error {
71     io::Error::new(io::ErrorKind::Other,
72                    "operation not supported on wasm yet")
73 }
74
75 pub fn decode_error_kind(_code: i32) -> io::ErrorKind {
76     io::ErrorKind::Other
77 }
78
79 // This enum is used as the storage for a bunch of types which can't actually
80 // exist.
81 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
82 pub enum Void {}
83
84 pub unsafe fn strlen(mut s: *const c_char) -> usize {
85     let mut n = 0;
86     while *s != 0 {
87         n += 1;
88         s = s.offset(1);
89     }
90     return n
91 }
92
93 pub unsafe fn abort_internal() -> ! {
94     ::intrinsics::abort();
95 }
96
97 // We don't have randomness yet, but I totally used a random number generator to
98 // generate these numbers.
99 //
100 // More seriously though this is just for DOS protection in hash maps. It's ok
101 // if we don't do that on wasm just yet.
102 pub fn hashmap_random_keys() -> (u64, u64) {
103     (1, 2)
104 }