Files
marqdo/src/embedded_lib.rs
T
cflmyandCursor 2e65c055b8 Release v0.1.2: embedded stdlib, docs, and extension branch policy.
Embed lib/*.mq.md in binary; marqdo version --check; public writeback/subtask pages; restore /vscode-extension/ ignore. VSIX built from branch vscode-extension only (see doc/design/vscode-extension-commit.md).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 09:41:53 +08:00

33 lines
905 B
Rust

//! Official `lib/*.mq.md` baked into the binary (fallback when disk `lib/` is absent).
use include_dir::{include_dir, Dir};
static LIB: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/lib");
/// Read `lib/<remainder>` from the embedded tree (e.g. `text.mq.md`).
pub fn read_file(remainder: &str) -> Option<String> {
let key = remainder.replace('\\', "/");
LIB.get_file(&key)
.and_then(|f| f.contents_utf8().map(|s| s.to_string()))
}
pub fn has_file(remainder: &str) -> bool {
let key = remainder.replace('\\', "/");
LIB.get_file(&key).is_some()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn embedded_has_core_libs() {
assert!(has_file("text.mq.md"));
assert!(has_file("subtask.mq.md"));
assert!(has_file("writeback.mq.md"));
assert!(read_file("math.mq.md")
.unwrap()
.contains("host_math_add"));
}
}