-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
223 implement assetsread and assetsread bytes (#225)
* Impl, test, and docs. * read binary impl, test, and docs. * update lib test. * Fix test? * Might be faster.
- Loading branch information
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
|
||
pub fn read_binary(src: String) -> Result<Vec<u32>> { | ||
let src_file_bytes = match super::Asset::get(src.as_str()) { | ||
Some(local_src_file) => local_src_file.data, | ||
None => return Err(anyhow::anyhow!("Embedded file {src} not found.")), | ||
}; | ||
let result = src_file_bytes.iter().map(|x| *x as u32).collect::<Vec<u32>>(); | ||
// let mut result = Vec::new(); | ||
// for byt: Vec<u32>e in src_file_bytes.iter() { | ||
// result.push(*byte as u32); | ||
// } | ||
Ok(result) | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_assets_read_binary() -> anyhow::Result<()>{ | ||
let res = read_binary("print/main.eld".to_string())?; | ||
assert_eq!(res, [112,114,105,110,116,40,34,84,104,105,115,32,115,99,114,105,112,116,32,106,117,115,116,32,112,114,105,110,116,115,34,41]); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use anyhow::Result; | ||
|
||
pub fn read(src: String) -> Result<String> { | ||
let src_file_bytes = match super::Asset::get(src.as_str()) { | ||
Some(local_src_file) => local_src_file.data, | ||
None => return Err(anyhow::anyhow!("Embedded file {src} not found.")), | ||
}; | ||
let mut result = String::new(); | ||
for byte in src_file_bytes.iter() { | ||
result.push(*byte as char); | ||
} | ||
Ok(result) | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_assets_read() -> anyhow::Result<()>{ | ||
let res = read("print/main.eld".to_string())?; | ||
assert_eq!(res, r#"print("This script just prints")"#); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters