platter2/lib.rs
1//! A simple utility to serve you files on a `platter`
2//!
3//! `platter` works on both desktop and web, and returns a byte buffer of the file's contents.
4//! On desktop, `load_file` is backed by native file system APIs. On web, it is backed by an
5//! HTTP 'GET' request.
6//!
7//! To use `platter` on the web, you'll need to choose either the `stdweb` or `web-sys` feature and
8//! enable it. This determines which method of binding to browser APIs `platter` will use.
9
10#![deny(
11 bare_trait_objects,
12 missing_docs,
13 unused_extern_crates,
14 unused_import_braces,
15 unused_qualifications
16)]
17
18use std::{future::Future, io::Error as IOError, path::Path};
19
20/// Create a Future that loads a file into an owned Vec of bytes
21///
22/// It exists for loading files from the server with Javascript on the web, and providing a unified
23/// API between desktop and the web when it comes to file loading.
24///
25/// On desktop, the file will be loaded from disk relative to the current directory, and the Future
26/// will return instantly. On the web, a GET request will be made to the stringified version of the
27/// `path` and the Future will return when the HTTP request resolves.
28pub fn load_file(path: impl AsRef<Path>) -> impl Future<Output = Result<Vec<u8>, IOError>> {
29 platform::load_file(path)
30}
31
32// Select which platform implementation to use based on provided features
33
34#[cfg(not(target_arch = "wasm32"))]
35#[path = "desktop.rs"]
36mod platform;
37
38#[cfg(target_arch = "wasm32")]
39#[path = "web.rs"]
40mod platform;