updated readme
This commit is contained in:
parent
743a6d300a
commit
a6ba8928db
28
README.md
28
README.md
@ -1,8 +1,12 @@
|
|||||||
Simple way to use [`include_bytes!`](https://doc.rust-lang.org/std/macro.include_bytes.html) for directories.
|
Simple way to use [`include_bytes!`](https://doc.rust-lang.org/std/macro.include_bytes.html) for directories.
|
||||||
|
|
||||||
|
# Why
|
||||||
|
|
||||||
|
I wanted to include a directory for my microcontroller project, but none of the solutions I used before seems to work in a no_std environment.
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
|
|
||||||
You can embed files two ways.
|
You can embed files three ways.
|
||||||
|
|
||||||
## Bytes mode
|
## Bytes mode
|
||||||
|
|
||||||
@ -39,3 +43,25 @@ fn main(){
|
|||||||
println!("{file}");
|
println!("{file}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Mime mode
|
||||||
|
Same as "Bytes mode" but also add the guessed mime type from [`mime_guess`](https://crates.io/crates/mime_guess).
|
||||||
|
Defaults to `application/octet-stream` for unknown types.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use dir_embed::Embed;
|
||||||
|
|
||||||
|
#[derive(Embed)]
|
||||||
|
#[dir = "../web/static"] // Path is relativ to the current file
|
||||||
|
#[mode = "mime"]
|
||||||
|
pub struct Assets;
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
let file: (&[u8],&str) = Assets::get("css/style.css").expect("Can't find file");
|
||||||
|
|
||||||
|
let string = str::from_utf8(file.0).expect("Failed to parse file");
|
||||||
|
|
||||||
|
println!("{string}");
|
||||||
|
println!("MIME: {file.1}"); // text/css
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user