feat(hololake): complete public runtime loop
This commit is contained in:
parent
71cece74b0
commit
92cce27973
26 changed files with 2626 additions and 79 deletions
|
|
@ -16,6 +16,12 @@ pub fn now() -> String {
|
|||
.map(|d| format!("{}.{:03}Z", d.as_secs(), d.subsec_millis()))
|
||||
.unwrap_or_else(|_| "0Z".into())
|
||||
}
|
||||
pub fn now_unix_ms() -> u128 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|duration| duration.as_millis())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
pub fn id(prefix: &str) -> String {
|
||||
format!("{}-{}", prefix, UuidPart::new())
|
||||
}
|
||||
|
|
@ -35,6 +41,14 @@ pub fn sha(bytes: &[u8]) -> String {
|
|||
}
|
||||
|
||||
pub fn root(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
if let Some(value) = std::env::var_os("HOLOLAKE_RUNTIME_TEST_ROOT") {
|
||||
let path = PathBuf::from(value);
|
||||
if !path.is_absolute() || !path.starts_with(std::env::temp_dir()) {
|
||||
return Err("HOLOLAKE_RUNTIME_TEST_ROOT_OUT_OF_SCOPE".into());
|
||||
}
|
||||
fs::create_dir_all(&path).map_err(|e| e.to_string())?;
|
||||
return Ok(path);
|
||||
}
|
||||
let p = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
|
|
@ -43,10 +57,10 @@ pub fn root(app: &AppHandle) -> Result<PathBuf, String> {
|
|||
fs::create_dir_all(&p).map_err(|e| e.to_string())?;
|
||||
Ok(p)
|
||||
}
|
||||
fn read_json<T: serde::de::DeserializeOwned>(p: &Path) -> Result<T, String> {
|
||||
pub fn read_json<T: serde::de::DeserializeOwned>(p: &Path) -> Result<T, String> {
|
||||
serde_json::from_slice(&fs::read(p).map_err(|e| e.to_string())?).map_err(|e| e.to_string())
|
||||
}
|
||||
fn write_json<T: serde::Serialize>(p: &Path, v: &T) -> Result<(), String> {
|
||||
pub fn write_json<T: serde::Serialize + ?Sized>(p: &Path, v: &T) -> Result<(), String> {
|
||||
if let Some(x) = p.parent() {
|
||||
fs::create_dir_all(x).map_err(|e| e.to_string())?
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue